背景 background-color
<!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.0">
<title>Document</title>
<style>
.box {
width: 100px;
height: 50px;
background-color: pink;
margin: 20px auto;
position: relative;
}
.son {
width: 0;
height: 2px;
background-color: transparent;
position: absolute;
left: 50%;
transition: all 3s;
}
.box:hover .son {
left: 0;
width: 100%;
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="son"></div>
</div>
</body>
</html>
边框 border
<!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.0">
<title>Document</title>
<style>
.box {
width: 200px;
height: 50px;
margin: auto;
position: relative;
}
.son {
width: 0;
position: absolute;
left: 50%;
transition: all 2s;
}
.box:hover .son {
width: 95%;
left: 2%;
border-bottom: 3px solid blue;
}
</style>
</head>
<body>
<div class="box">
<div class="son"></div>
</div>
</body>
</html>