Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS rotation with respect to a reference point

Tags:

css

rotation

How to rotate an element with respect to a defined point i.e. defined x & y coordinate in CSS (webkit)?

Normally rotation make element's center point as reference.

like image 779
thecodeparadox Avatar asked Jul 09 '11 08:07

thecodeparadox


People also ask

How do I rotate an image with a point in CSS?

You could use transform-origin. It defines the point to rotate around from the upper left corner of the element. This would rotate around the upper left corner.

How do you apply rotation in CSS?

css file, stylesheet, or <style> tags, you can use the CSS class name in any of your image tags. To rotate an image by another measure of degrees, change the "180" in the CSS code and <img> tag to the degree you desire.

How do I rotate a Div 90 degrees?

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); In case of half rotation change 90 to 45 .

How do you rotate and translate in CSS?

The order is right to left, not left to right. transformation: translate(0,10%) rotate(25deg); The rotate operation is done first, then the translate .


1 Answers

You could use transform-origin. It defines the point to rotate around from the upper left corner of the element.

transform-origin: 0% 0% 

This would rotate around the upper left corner.

For other options look here: https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin

for the safer side if this link not available then here are a couple of more options

transform-origin: center; // one of the keywords left, center, right, top, and bottom  transform-origin: top left; // same way can use two keywords  transform-origin: 50px 50px; // specific x-offset | y-offset  transform-origin: bottom right 60px; // third part is for 3D transform : z-offset 

As far as I know there isn't an option to rotate around a fixed point (although this would be handy).

like image 170
kufi Avatar answered Sep 30 '22 03:09

kufi