0

Why doesn't my animation "roll back" (animated) when the mouse leaves the button, just like it does when the mouse enters the button?

.container {
    padding: 20px 0 0 10px;
}
.button {
    color: #ffffff;
    background: #71b3c7;
    text-decoration: none;
    -webkit-backface-visibility: hidden;
    -webkit-transition: border-color 0.4s, color 0.4s;
    transition: border-color 0.4s, color 0.4s;
    position: relative;
    text-align: center;
    padding: 8px 14px;
    font-size: 20px;
    text-transform: uppercase;
    font-family: "Open Sans", Arial, sans-serif;
    font-weight: bold;
    letter-spacing: 1.4px;
}
.button span {
    position: relative;
    z-index: 2;
}
.button:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0;
    -webkit-transform: scale3d(0.1, 1, 1);
    transform: scale3d(0.1, 1, 1);
    -webkit-transition: -webkit-transform 0.4s, opacity 0.4s;
    transition: transform 0.4s, opacity 0.4s;
    -webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
    transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
    -webkit-transform-origin-x: 0;
}
.button:hover {
    color: #fff;
}
.button:hover:before {
    opacity: 1;
    background: #2a9276;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}
<div class="container">
    <a href="#" class="button"><span>button</span></a>
</div>

CodePen link

TylerH
  • 20,799
  • 66
  • 75
  • 101
Mathijs Delva
  • 211
  • 5
  • 17
  • 1
    The non-hover version of the pseudoelement doesn't have background defined, so it goes from `#2a9276` to `transparent` instantly. https://codepen.io/anon/pen/POQjBw – pawel Nov 20 '17 at 15:09
  • add the transition effect to :hover and it will probably work – Alvaro Menéndez Nov 20 '17 at 15:20
  • See also https://stackoverflow.com/questions/16516793/css3-reverse-animation-on-mouse-out-after-hover and https://stackoverflow.com/questions/10995165/css-opposite-of-hover-on-mouse-leave – TylerH Nov 20 '17 at 16:30

0 Answers0