4

I am trying to animate the text using keyframes in css :

my html code:

@keyframes animate {
  0% {
    content: "Animate"
  }
  50% {
    content: "text using"
  }
  100% {
    content: "CSS!!"
  }
}

.change-text::after {
  animation: animate 5s infinite;
}
<center>
  <p class="change-text">
    Text will change here
  </p>
</center>

But the text is not changing, help me figure out what is wrong with my code?

2
  • And what does that mean? What animation are you trying to apply? What's the starting point, what's the end point, what happens in the middle? Where did you get stuck? "I am trying" is not a problem description, so what problem are you facing? Commented Sep 14, 2019 at 13:25
  • Note that the <center> element has been obsolete for a decade or more. Commented Sep 14, 2019 at 13:42

2 Answers 2

3

this is happening because you have not given content property in after. just add content: ""; into to .change-text::after

@keyframes animate{
  0%{
    content : "Animate"
  }
  50%{
    content : "text using"
  }
  100%{
    content : "CSS!!"
  }
}
.change-text::after{
  animation : animate 5s infinite;
  content: ""; // Added 
}
<center>
  <div class="change-text">
    Text will change here
  </div>
</center>

Sign up to request clarification or add additional context in comments.

Comments

1

You can try this:

Html Code:

<center>
  <p class="change-text">
    Text will change here
    <span class="animated-text"></span>
  </p>
</center>

CSS Code

@keyframes animate{
    0%{
        content : "Enjoy";
    }
    20%{
        content : "animate";
    }
    50%{
        content : "text";
    }
    75%{
        content : "using";
    }
    100%{
        content : "CSS!!";
    }
}
.animated-text::after{
    content: ''; // Need to Add content
    color: red;
    animation : animate 5s infinite;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.