David Royo Virgili David Royo Virgili - 20 days ago 6
CSS Question

Why doesn't transition css property revert the animation when it's unhovered?

Why doesn't the transition property do the reverted animation when I unhover?

I thought that when you cancel a

transform
it does the reverted animation.



body {
background-color : #333333;
}

.corner {
background-color : rgb(207, 207, 207);
border-bottom-right-radius: 100%;
height : 50px;
left : 0px;
position : fixed;
top : 0px;
width : 50px;
}

.corner:hover {
transform : rotateX(180deg) rotateY(180deg) rotateZ(180deg);
transition: all .5s ease-in-out;
}

#top-right {
left :auto;
right : 0px;
top : 0px;
transform: rotate(90deg);
}

#bottom-left {
bottom :0;
left :0px;
right : auto;
top : auto;
transform: rotate(-90deg);
}

#bottom-right {
bottom :0px;
left :auto;
right : 0px;
top : auto;
transform: rotate(180deg);
}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rentats Royo</title>
<link rel="stylesheet" href="css/styles.css">
<style type="text/css">
</style>
</head>
<body>
<div class="corner"></div>
<div class="corner" id="top-right"></div>
<div class="corner" id="bottom-left"></div>
<div class="corner" id="bottom-right"></div>
</body>
</html>




Answer

The problem is that the transition property is defined in the:hover pseudo-class instead of being declared in the normal state of the element.

You can read this post for further detail.

body {
  background-color : #333333;
}

.corner {
  background-color          : rgb(207, 207, 207);
  border-bottom-right-radius: 100%;
  height                    : 50px;
  left                      : 0px;
  position                  : fixed;
  top                       : 0px;
  width                     : 50px;
  transition                : all .5s ease-in-out;
}

.corner:hover {
    transform : rotateX(180deg) rotateY(180deg) rotateZ(180deg);
}

#top-right {
    left     :auto;
    right    : 0px;
    top      : 0px;
    transform: rotate(90deg);
}

#bottom-left {
    bottom   :0;
    left     :0px;
    right    : auto;
    top      : auto;
    transform: rotate(-90deg);
}

#bottom-right {
    bottom   :0px;
    left     :auto;
    right    : 0px;
    top      : auto;
    transform: rotate(180deg);
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Rentats Royo</title>
  <link rel="stylesheet" href="css/styles.css">
  <style type="text/css">
  </style>
</head>

<body>
  <div class="corner"></div>
  <div class="corner" id="top-right"></div>
  <div class="corner" id="bottom-left"></div>
  <div class="corner" id="bottom-right"></div>
</body>

</html>

Comments