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

CSS Button Animation Not Starting

I’m creating a basic css animation for a restart button. The button is basically going to shrink and grow infinitely. It’s for a rock paper scissor game. I’m only going to put the relevant code here. Idk why the animation isn’t working. Take a look at the html and CSS code.

<div id="gameOver" class="gameOver">
        <p id="finalResult">Game Over! You Lost/Won</p>
        <button id="restartButton">Restart</button>
</div>

CSS:

#restartButton {
    width: 17%;
    height: 100px;
    cursor: pointer;
    color:rgb(255, 197, 249);
    font-size: 3.5em;
    border-style: solid;
    border-width: 5px;
    border-color: white;
    background-color: rgb(42, 40, 40);
    border-radius: 35px;
    transition: 0.4s;
    animation-name: example 5s infinite;
}

@keyframes example {
    from {height: 100px; width: 17%;}
    to {height: 80px; width: 14%;}
  }

#restartButton:hover {
    transition: 0.4s;
    border-radius: 75px;
    color: rgb(42, 40, 40);
    background-color: rgb(255, 197, 249);
}

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

>Solution :

animation-name only sets the name of the animation. animation is a shorthand for several properties.

#restartButton {
  width: 17%;
  height: 100px;
  cursor: pointer;
  color: rgb(255, 197, 249);
  font-size: 3.5em;
  border-style: solid;
  border-width: 5px;
  border-color: white;
  background-color: rgb(42, 40, 40);
  border-radius: 35px;
  transition: 0.4s;
  animation: example 5s infinite;
}

@keyframes example {
  from {
    height: 100px;
    width: 17%;
  }
  to {
    height: 80px;
    width: 14%;
  }
}

#restartButton:hover {
  transition: 0.4s;
  border-radius: 75px;
  color: rgb(42, 40, 40);
  background-color: rgb(255, 197, 249);
}
<div id="gameOver" class="gameOver">
  <p id="finalResult">Game Over! You Lost/Won</p>
  <button id="restartButton">Restart</button>
</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