Is there any way to set style transform: translateX(100px) translateY(200px) rotate(100deg) scale(1.5) on multiple places? For example, there are these lines in CSS:
.translate-x {
transform: translateX(100px);
}
.translate-y {
transform: translateY(200px);
}
.rotate {
transform: rotate(100deg)
}
.big {
transform: scale(1.5);
}
And then, I would like use these classes in HTML to combine transform.
<div class="translate-x rotate big"></div>
<div class="translate-y big"></div>
...
The problem is that the styles do not combine, but the last one will overwrite the others.
Only way what I know is combine all classes. But there are many combinations...
.translate-x.translate-y {
transform: translateX(100px) translateY(200px);
}
.translate-x.translate.y.big {
transform: translateX(100px) translateY(200px) scale(1.5);
}
...
Unfortunately, you cannot do it. Syntax for transform is as follows,
transform: none|transform-functions|initial|inherit;
So when you call multiple classes on your HTML element, only the last class declared in your CSS is applied. (class order doesn't matter in HTML)
The best you can do is use CSS preprocessor with a function which will generate a string of these transform functions called in one declaration so that they don't override.
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