纯CSS实现下拉菜单
将下拉菜单的ul高度设置为0,并且超出部分隐藏掉。
设置下拉菜单的高度添加过渡效果,高度为auto时过渡效果失效。
<style> ul{ list-style: none; margin: 0; padding: 0; } ul li a{ display: block; text-decoration: none; width: 100px; height: 50px; text-align: center; line-height: 50px; color: white; background-color: #2f3e45; } .drop-down{ width: 100px; height: 50px; } .drop-down-content{ opacity: 0; height: 0; overflow: hidden; transition: all 1s ease; } p{ font-size: 20px; margin: 0; } .drop-down-content li:hover a{ background-color: red; } .nav .drop-down:hover .drop-down-content{ opacity: 1; height: 150px; } </style> <ul class="nav"> <li class="drop-down"> <a href="#">下拉菜单</a> <ul class="drop-down-content"> <li><a href="#">菜单1</a></li> <li><a href="#">菜单2</a></li> <li><a href="#">菜单3</a></li> </ul> </li> </ul> <p>内容</p>
效果图如下:
相关推荐
Mexican 2011-01-20
zhrookie 2012-02-03
89307547 2016-11-29
luckyeyefocus 2017-05-22
javadeaihaozhe 2018-01-05
tthappyer 2018-11-27
deng 2007-11-29
ThikHome 2018-01-05
zhanghaibing00 2017-05-22
WRITEFORSHARE 2016-11-29
huakaiwuxing 2016-10-20
libowen0 2019-06-28
tthappyer 2014-12-15
LadyZhong 2014-03-25
zljiaa 2014-03-01
83493467 2014-02-28