I trying to rotate a div on a page and have it rest right up against the left side of its parent element (the body in this case). I know about transform-origin but no matter what values I insert it doesn't align correctly.
http://jsfiddle.net/QpHCM/
HTML
<div class="handle">Text</div>
CSS (Sass)
$transform: rotate(90deg);
$transform-origin: 0 0;
body {
border: 1px solid red;
}
.handle {
width: 50px;
height: 15px;
background: blue;
color: white;
text-align: center;
padding: 5px;
line-height: 15px;
transform: $transform;
-moz-transform: $transform;
-webkit-transform: $transform;
transform-origin: $transform-origin;
-moz-transform-origin: $transform-origin;
-webkit-transform-origin: $transform-origin;
}
This is driving me mad. Can anyone get the rotated element aligned to top: 0, left:0 in the body when rotated?
Since the rotation is around the center of the element, its not aligned with left: 0. use: $transform: rotate(90deg) translate(0, -25px);
To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.
An element can be rotated 90 degrees by using the transform property. This property is used to move, rotate, scale and others to perform various kinds of transformation to elements. The rotate() transformation function can be used as the value to rotate the element.
We can add the following to a particular tag in CSS: -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg);
Since the rotation is around the center of the element, its not aligned with left: 0.
use:
$transform: rotate(90deg) translate(0, -25px);
the negative half of element width gets you there.
working example.
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