What is the preferred solution to rotating then aligning text to the side of some content?
Example: http://jsfiddle.net/nVtpz/
<style>
.wrapper {
width: 100px;
height: 100px;
border: 1px solid #009;
margin: 50px;
}
.text
{
border: 1px solid #900;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.image {
border: 1px solid #090;
}
</style>
<div class="wrapper">
<div class="text">
Text to rotate
</div>
<div class="image">
<img src="http://lorempixel.com/100/100"/>
</div>
</div>
I want the text to be aligned next to the bottom left corner of the image (but not on top of the image, i.e. without float)
I guess I could use position: relative; bottom: 0px
or something similar, but is there a better way?
I think that this is what you are going for, but you can change the transform origin using transform-origin
(with related vendor prefixes as needed). This is situational, but in your case:
transform: rotate(90deg) translateX(100%);
transform-origin: 100% 100%;
.wrapper {
position: relative;
width: 100px;
height: 100px;
}
.text{
position: absolute;
width: 100%;
background:rgba(0,0,0,0.5);
color:#fff;
-webkit-transform: rotate(270deg) translateX(-100%);
transform: rotate(270deg) translateX(-100%);
-webkit-transform-origin: 0px 0px;
transform-origin: 0px 0px;
}
.image img{
vertical-align:middle;
}
<div class="wrapper">
<div class="text">
Text to rotate
</div>
<div class="image">
<img src="http://lorempixel.com/100/100"/>
</div>
</div>
To rotate text simply:
.container {
writing-mode: vertical-rl;
text-orientation: sideways;
}
Then set it in a CSS grid so it can track the viewport using sticky
if you want it to move on scroll.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With