鼠标移入下划线展开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鼠标移入下划线展开</title>
<style type="text/css">
#underline{
width: 200px;
height: 50px;
background: #ddd;
margin: 20px;
position: relative;
}
#underline:after{
content: "";
width: 0;
height: 5px;
background: blue;
position: absolute;
top: 100%;
left: 50%;
transition: all .8s;
}
#underline:hover:after{
left: 0%;
width: 100%;
}
</style>
</head>
<body>
<div id="underline"></div>
</body>
</html>
鼠标移入背景展开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鼠标移入背景展开</title>
<style>
span{
display: inline-block;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
position: relative;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
span:after{
content: "";
background-color: #f00;
position: absolute;
top: 0;
bottom: 0;
right: 50%;
left: 50%;
z-index: -1;
transition: 0.3s;
}
span:hover:after{
right: 0;
left: 0;
}
</style>
</head>
<body>
<span>按钮</span>
</body>
</html>