<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0px;
padding: 0px;
list-style: none;
}
.one{
width: 150px;
margin: 50px auto;
}
.one ul{
height: 40px;
width: 150px;
background-color: blue;
overflow: hidden;
transition:0.3s
}
.one ul li{
height: 40px;
width: 150px;
line-height: 40px;
text-align: center;
}
.one:hover ul{
height: 160px;
}
.one li:hover{
background-color: rgb(19, 19, 141);
}
</style>
</head>
<body>
<div class="one">
<ul>
<li>5555555555</li>
<li>2222222222</li>
<li>5555555555</li>
<li>4444444444</li>
</ul>
</div>
</body>
</html>
描述:先设置div的宽高(在没有hover时,想要显示的宽高),然后设置overflow: hidden;设置ul的宽高,width=div的宽,height=div的高li的个数,设置过渡时间0.3s;当hover ul时,div的height设置为div的高li的个数
效果图:
-
hover ul前
-
hover ul后