CSS hover not working after initial animation

Refresh

April 2019

Views

0 time

1

I have a basic button, which I animate initially. But once animated, I want to add a new animation on hover; but it seems to not work for some reason.

For example:

button animation:

.container {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 100%;
  overflow: hidden;
}

.slide-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  background-color: #feffff;
  box-shadow: 0 2px 20px 0 #686f7638;
  margin-top: 10px;
  width: 45px;
  height: 45px;
  animation: testing 1s ease-in forwards;
}

.slide-btn:hover {
  transform: scale(1.5);
}

@keyframes testing {
  to {
    transform: translateX(100px);
  }
}
<div class="container">
  <div class="slide-btn">></div>
</div>

My guess is that for the CSS animation I'm using forwards, but I really need forwards to be there.

1 answers

1

Yes, it's because the forwards that make the animation to override the transform. Instead of forwards you can do like below:

.container {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 100%;
  overflow: hidden;
}

.slide-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  background-color: #feffff;
  box-shadow: 0 2px 20px 0 #686f7638;
  margin-top: 10px;
  width: 45px;
  height: 45px;
  transform: translateX(100px);
  transition:0.5s;
  animation: testing 1s ease-in;
}

.slide-btn:hover {
  transform: translateX(100px) scale(1.5);
}

@keyframes testing {
  from {
    transform: translateX(0px);
  }
}
<div class="container">
  <div class="slide-btn">></div>
</div>