Animation in Before overwriting text

Asked

Viewed 115 times

-2

I’m trying to make an animation on the ::before of a paragraph every time I pass the mouse

But this CSS is overwriting everything written in the paragraph, even though it is Before instead of After.

	p::before{
    	width:200px;
        height:20px;
        position: absolute;
        content: "";
    }
	p:hover::before{
    	animation: blink 2s infinite alternate;
    }
    
    @keyframes blink {
        from {
            background-color: #89F0FF;
            box-shadow: 0 0 10px #89F0FF;
        }
        to {
            background-color: white;
            box-shadow: 0 0 10px #89F0FF;
        }
    }
<p>Passe o Mouse Aqui</p>

1 answer

1


You need the z-index, in the case of Absolute, it usually takes the front, so you need to specify the text as the front of it, or in the case what is Absolute backwards.

You can sort the following way (with z-index: -1) to send back, or add a span inside the p and put as position relative and z-index: 1.

p::before {
  width: 200px;
  height: 20px;
  position: absolute;
  content: "";
  z-index: -1;
}

p:hover::before {
  animation: blink 2s infinite alternate;
}

@keyframes blink {
  from {
    background-color: #89F0FF;
    box-shadow: 0 0 10px #89F0FF;
  }
  to {
    background-color: white;
    box-shadow: 0 0 10px #89F0FF;
  }
}
<p>Passe o Mouse Aqui</p>

  • It worked, thank you. Only by adding a detail that if <p> is on top of another <div> with background, that <div> must be z-index:0 and the <p> z-index:-1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.