Which CSS class gets the "transition"?
Most CSS transition examples showed two classes. And "transition" and related properties are set on one of them. But at first I didn't understand why things were on one and not the other. Or even on both. And transitions in my own code didn't always happen when I expected them.
But the actual rule is simple: Transitions only happen if the transition property is part of an element's current styles.
If we have class
If the transition is on
Or
But the actual rule is simple: Transitions only happen if the transition property is part of an element's current styles.
If we have class
foo
and class foo:hover
and the transition is on foo
, it always happens. Because the foo
style is always applied.If the transition is on
foo:hover
, then the transition happens when you hover. But everything snaps back instantly when the mouse moves away, because foo:hover
styles are no longer applied.Or
foo
and foo:hover
can have different transitions, such as ones with different speeds. The transition on foo:hover
applies when you mouse over the element, because foo:hover
is more specific so it's version wins. But the moment the mouse moves away, the transition defined on foo
applies.
Comments
Post a Comment