Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Transforms: Multiple Origins?

Is it possible to specify an origin at the top left (0%, 0%) for scaling, and a different origin (center) for rotation in CSS3? I am only working with webkit, if that helps.

I am currently using a transform list (i.e. -webkit-transform: scale(newScale) rotate(newRotate)

but it seems like it isn't possible to change the origin in-between passes. Is there a better way to look at this? Presently, if I scale an object and rotate it with an origin at the default center, the position of the element is now off and so when you drag the element, the cursor is still at the top left of the element, whereas it should be at the center. Changing the origin to the center to scale it fixes this, but presents new problems with rotation and flipping.

like image 276
David Avatar asked Jan 20 '12 19:01

David


People also ask

How do you add multiple transform properties in CSS?

Just start from there that in CSS, if you repeat 2 values or more, always last one gets applied, unless using ! important tag, but at the same time avoid using ! important as much as you can, so in your case that's the problem, so the second transform override the first one in this case...

Can you have two transform CSS?

Multiple transforms can be applied to an element in one property like this: transform: rotate(15deg) translateX(200px); This will rotate the element 15 degrees clockwise and then translate it 200px to the right.

When adding multiple transformations in a single transform property separate them with?

In the example below, we'll use multiple values of the transform property. It is possible to add multiple values applied one after another. The values must be separated by space. The transform property applies the rightmost value, and then the values on the left.

What is CSS transform origin?

The transform origin is the point around which a transformation is applied. For example, the transform origin of the rotate() function is the center of rotation. In effect, this property wraps a pair of translations around the element's other transformations.


1 Answers

Found a good solution to the problem... by creating a parent/child relationship as follows:

<div class="container">
   <img src="" />
</div>

I can now setup two classes as follows:

.container {
    -webkit-transform-origin: 0% 0%;
    -webkit-transform: scale(0.5);
}

.container img {
    -webkit-transform-origin: 50% 50%;
    -webkit-transform: rotate(45deg);
}

This will do exactly what I want: scale with an origin at the top left, then rotate with the origin at the center. Voila!

like image 73
David Avatar answered Oct 15 '22 22:10

David