Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Transition delay only on hover out

How do I only apply the transition-delay on hover out only?

For example, if you hover over the div, the overlaydiv::before should appear, it will delay for 1s as expected for hover in because I set the transition-delay on it, but I only want this delay on hover out.

I found this article but it’s not relevant in my case
How to reset/control transition delay when hover out?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

div {
  width: 300px;
  height: 300px;
  background-color: blue;
  position: relative;
}

div::before {
  content: '';
  position: absolute;
  background-color: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100%;
  opacity: 0;
  transition-delay: 1s;
}

div:hover::before {
  opacity: 1;
}
<div></div>

>Solution :

You can try

div::before {
  content: '';
  position: absolute;
  background-color: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: .5s ease-in-out 1s;
}

div:hover::before {
  opacity: 1;
  transition: .0s ease-in-out 0s; 
}

It will have transition delay only on hover-out

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading