Your answer
You have added the transition
property on the hover state of the element. Therefore the transition
is not applied when you leave the cursor
from the element.
.shape1{
position: absolute;
background: red;
top: 512px;
width: 180px;
height: 140px;
transition: .2s ease; /* move this here from :hover */
}
Further information
Besides this you can also add specific properties to the transition
. For example, if you only want the height to be animated you could it like this:
.shape1?{
transition: height .2s ease;
/* this inly affects height, nothing else */
}
You can even define different transition-times for each property:
.shape1?{
transition: height .2s ease, background-color .5s linear;
/* stacking transitions is easy */
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…