I am trying to rotate an image using a CSS
transform such that it stays correctly aligned within the surrounding div
, i.e. the top left corner of the image should be aligned with the top left corner of the div
.
As you can see here (-> click on [rotate]
) this does not work. Is there a way to fix this?
(Note that I'd be using this in an online image viewer so I cannot hardcode an offset for the rotated image. There's a lot of similar questions but I haven't found this exact question.)
I don't know if there is a simplier way, but you can set margin of the image after rotation like this.
You can use js to get image width and height so it sets values accordingly to the size of image. I used manual way.
http://jsfiddle.net/YQktn/3/
EDIT:
You can always mess with
as found here: CSS "transform: rotate()" affecting overall design with "position: absolute" (not aligning properly)