I want to center some text in two corners of an image, one in the top left and other in the top right. Something like this:
.left,
.right {
width: 300px;
height: 200px;
float: left;
}
.left-div,
.right-div {
position: relative;
}
.left-text,
.right-text {
position: absolute;
top: 0;
left: 0;
z-index: 999;
background-color: black;
color: white;
padding: 5px;
}
.left {
float: left;
}
.right {
float: right;
}
.rotate-left {
-moz-transform: translateX(-50%) translateY(-50%) rotate(-90deg);
-webkit-transform: translateX(-50%) translateY(-50%) rotate(-90deg);
transform: translateX(-50%) translateY(-50%) rotate(-90deg);
}
.rotate-right {
-moz-transform: translateX(50%) translateY(50%) rotate(90deg);
-webkit-transform: translateX(50%) translateY(50%) rotate(90deg);
transform: translateX(50%) translateY(50%) rotate(90deg);
}
<div id="row">
<div class="left-div">
<img class="left" src="http://keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg" />
<p class="left-text rotate-left">
text 1
</p>
</div>
<div class="right-div">
<img class="right" src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image2.jpg" />
</div>
<p class="right-text rotate-right">
text 2
</p>
</div>
for some reasons the paragraphs with text are not centered where they are supposed to be, I don't know why?
Here is My JS FIDDLE
When using
rotate
you need to adjust from where usingtransform-origin
to control its position after the rotation.Sample 2, positioned outside the image
You may use flex and writing-mode.
example:
Pen to fork and play with
or did i misunderstood where you wanted these to stand ?