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

Animate pseudo element ::before on hover

I have the below structure and I want to animate that once I hover over h1, I have below css which doesn’t work not sure where I am doing things wrong.

How can I animate with CSS only as I don’t want to use JS? The animation could be scaled or skewed.

CodepenCode

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

.wrapper{
  width:200px;
  margin:100px auto;
}
.wrapper h1::before {
  content: url('https://i.ibb.co/Bg4jS5B/hat-1-e1713504486338.png'); 
  display: inline-block;
  margin-left: -25px; 
  margin-top: -35px; 
  width:30px;
  position: absolute;
  /*filter: brightness(0) invert(1);*/
  transition: all 0.3s ease-in-out;
}
.wrapper h1::before:hover {
  cursor:progress;
  transform: scale(1.2); 
}
<div class="wrapper">
  <h1>About Us</h1>
</div>

>Solution :

You :hover part is wrong here, use it like this:

.wrapper{
  width:200px;
  margin:100px auto;
}

.wrapper h1::before {
  content: url('https://i.ibb.co/Bg4jS5B/hat-1-e1713504486338.png'); 
  display: inline-block;
  margin-left: -25px; 
  margin-top: -35px; 
  width:30px;
  position: absolute;
  /*filter: brightness(0) invert(1);*/
  transition: all 0.3s ease-in-out;
}

.wrapper h1:hover::before {
  cursor: progress;
  transform: scale(1.2);
}
<div class="wrapper">
  <h1>About Us</h1>
</div>
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