I need to animate both of the element and its pseudo element.
Then I noticed, when I hover, everything is fine. But then I stop hovering, the Home
animates first and after that, the pseudo element Link
starts animating.
Why it behaves like this? Is there a way to make them animate simultaneously?
Here's a simplified recreation of my problem:
a {
color: blue;
transition: all 1s;
text-decoration: none;
}
a:hover {
color: red;
font-size: 48px;
}
a:hover::before {
color: green;
font-size: 32px;
}
a::before {
content: 'Link:';
transition: all 1s;
}
<a href="javascript: void(0)">Home</a>
I'm using MacOS with Chrome Version 83.0.4103.97 (Official Build) (64-bit)
If you can't reproduce the problem, here's a screengrab of it:
The transition-delay CSS property specifies the duration to wait before starting a property's transition effect when its value changes.
The transition-delay property specifies when the transition effect will start. The transition-delay value is defined in seconds (s) or milliseconds (ms).
You can use transitions to delay the :hover effect you want, if the effect is CSS-based. this will delay applying the the hover effects ( background-color in this case) for one second.
Definition and Usage. The transition-property property specifies the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes). Tip: A transition effect could typically occur when a user hover over an element.
I also assigned the default values to ::before
and works fine. I think it trying to inherit the default values and it's confusing.
a {
color: blue;
transition: all 1s;
text-decoration: none;
}
a:hover {
color: red;
font-size: 48px;
}
a::before {
content: 'Link:';
transition: all 1s;
font-size: 1rem;
color: blue;
}
a:hover::before {
color: green;
font-size: 32px;
}
<a href="javascript: void(0)">Home</a>
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