This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
From now on you can transform elements with the translate
, rotate
, and scale
properties.
Let’s say you apply several transforms to an element, and on :hover
and :focus
you only want to change one of them, for example, scale
.
<button>Transform</button>
button {
transform: translateX(20px) rotate(15deg) scale(1);
}
button:is(:hover, :focus) {
transform: scale(2);
}
That doesn't work as expected because by setting transform: scale(2)
you're overwriting all the previously defined transforms. To fix that, you have to repeat the other transforms.
button {
transform: translateX(20px) rotate(15deg) scale(1);
}
button:is(:hover, :focus) {
transform: translateX(20px) rotate(15deg) scale(2);
}
That can cause a lot of repetition in your code.
Individual transform properties fix that issue because now you can use translate
, rotate
, and scale
separately.
button {
translate: 20px 0;
rotate: 15deg;
scale: 1;
}
button:is(:hover, :focus) {
scale: 2;
}
This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Manuel Matuzović | Sciencx (2022-12-26T09:38:54+00:00) Day 66: individual transform properties. Retrieved from https://www.scien.cx/2022/12/26/day-66-individual-transform-properties/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.