Using CSS3, HTML (and javascript/jquery if needed), I need to rotate an image 90/270 degrees and have it position to fill its parent div/container. Sounds simple, but when images are rotated, there positioning changes and I can't figure out how or why.
Here is a jsFiddle to explain - http://jsfiddle.net/UPGkU/2/ - I just want the blue logo to be position exactly within the red div.
Of course, I could use specific offsets, but if a different image is used, those offsets change, so I really want to find a generic solution.
Any help would be fantastic, thanks!
Answer. Answer: Rotate tool is used to rotate the position of a image.
A couple of options: Image > Transform > Rotate 90 Degrees Right ( do this twice) Image > Transform > Rotate... and set 180. Image > Transform > Flip Vertical (not quite you asked for but may suffice)
Manually rotate a picture or shape Select the picture or shape. Manually rotate the text box by selecting the shape or picture rotation handle and dragging in the direction you want. To keep the rotation to 15 degree angles, press and hold Shift while you drag the rotation handle.
You need to set a transform-origin
- in this scenario, a point around which the image gets rotated.
#image {
-webkit-transform: rotate(90deg);
-webkit-transform-origin: 0 0; //initially 50% 50%
margin-left: 100%;
}
90deg fiddle / 270deg fiddle
Update:
The challenge with the latter is that we can't really modify transform-origin
as its position is relative to the not yet transformed element and we can't just set margin-top:100%
since margin values (even vertical ones) are calculated as a percentage always relative to the width of the containing block. The following code should work:
#image {
-webkit-transform: rotate(-90deg);
-webkit-transform-origin: 0 0;
position:relative;
top:100%;
}
try with
#image {
-webkit-transform: rotate(90deg);
-webkit-transform-origin: 0 100%;
position : relative;
top : -50px;
}
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