Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - add transform to element without removing the existing one [duplicate]

Tags:

So, I have a div, like this:

<div class="rotate-90"></div>

and the css:

.rotate-90
{
    transform: rotate(90deg);
}

and I want to add another class to the div, named "scale-2", like this:

<div class="rotate-90 scale-2"></div>

.scale-2
{
    transform: scale(2);
}

but when I try to combine them, the second class overrides the first one, so I get only a scaled div, and not rotated. So, how can I combine the transforms without writing the code twice or combining the classes codes?

Thanks :)

like image 732
StyleSh1t Avatar asked Aug 22 '16 12:08

StyleSh1t


People also ask

How do you add more than one transform 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 multiple transforms 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 skew in CSS?

CSS Demo: skew() This transformation is a shear mapping (transvection) that distorts each point within an element by a certain angle in the horizontal and vertical directions. The effect is as if you grabbed each corner of the element and pulled them along a certain angle.


1 Answers

Transform-rules get overridden, like any other rules.

You can however combine the transforms in one rule:

.rotate-90.scale-2 {
    transform: rotate(90deg) scale(2);
}

If combining the two classes isn't your wish (which I totally don't understand, but respect), and if your framework only has these two effects, than you could use zoom for the scale-rule:

.scale-2 {
    zoom: 2;
}
like image 174
Sebastian G. Marinescu Avatar answered Sep 17 '22 10:09

Sebastian G. Marinescu