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" >
<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);
}
CodePudding user response:
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" >
<p id="finalResult">Game Over! You Lost/Won</p>
<button id="restartButton">Restart</button>
</div>
CodePudding user response:
#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;
transition-property: transform;
transition: 0.4s;
}
#restartButton:hover {
border-radius: 75px;
color: rgb(42, 40, 40);
background-color: rgb(255, 197, 249);
animation: example 5s infinite;
}
@keyframes example {
from {
transform: scale(0.1);
}
to {
transform: scale(20);
}
}
<div id="gameOver" >
<p id="finalResult">Game Over! You Lost/Won</p>
<button id="restartButton">Restart</button>
</div>