Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a delay for the transition of my pseudo elements?

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:

glitch

like image 916
Hao Wu Avatar asked Jun 16 '20 01:06

Hao Wu


People also ask

What is transition-delay?

The transition-delay CSS property specifies the duration to wait before starting a property's transition effect when its value changes.

What is the property is used to set delay for transition?

The transition-delay property specifies when the transition effect will start. The transition-delay value is defined in seconds (s) or milliseconds (ms).

How do you delay hover in CSS?

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.

What is transition property in CSS?

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.


1 Answers

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>
like image 57
doğukan Avatar answered Sep 29 '22 15:09

doğukan