- hover时设置的效果离开时平滑过渡:
<!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<title>hover平滑过渡效果</title>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
position: relative;
transition: all 1s linear; //这个是关键
}
div:hover {
//这里可以写任何动画效果,比如放大、缩小,
//但是不可以写如 display:block -> display:none 这种非线性变化
opacity: 0;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 较为复杂的结构中的hover效果
<!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<title>hover平滑过渡效果</title>
<head>
<style>
div{ position: relative; float: left; box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.2); }
div img{ margin: 20px auto; margin-top: 40px; width: 40%; display: block; }
div h5{ line-height: 40px; margin: 0px; text-align: center; }
div p{ width: 84%; margin: 1em auto; }
div span{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #ff0000; color: #FFF; padding: 14%; box-sizing: border-box; }
div:hover span, div:active span{
opacity: 1;
}
div span{
transition: all 0.3s linear;
opacity: 0;
}
</style>
</head>
<body>
<div>
<img src="images/icon_01.png" />
<h5>标题</h5>
<p>副标题</p>
<span>详细文本</span>
</div>
</body>
</html>