css下拉菜单
小毛2019-06-15 12:03:212341 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 摘要:
运用display属性设置下拉菜单
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< style >
*{margin: 0;padding: 0;}
body{
background: lightgray;
}
.page{
margin: 20px auto;
width: 600px;
background: lightcyan;
height: 1000px;
}
.nav>li{
float: left;
width: 150px;
text-align: center;
background: darkmagenta;
padding: 0px;
color: lightgrey;
line-height:50px;
}
ul{
list-style: none;
}
.dropdown-content{
display: none;
background: #0aa6ec;
}
.dropdown:hover .dropdown-content{
display: block;
}
</ style >
</ head >
< body >
< div class = "page" >
< ul class = "nav" >
< li >首页</ li >
< li class = "dropdown" >新闻
< ul class = "dropdown-content" >
< li >国际新闻</ li >
< li >国内新闻</ li >
</ ul >
</ li >
< li >产品</ li >
< li >联系我们</ li >
</ ul >
</ div >
</ body >
</ html >
|
效果图
总结:
设置下拉菜单的display属性为隐藏,通过li的hover,更改下拉菜单的display属性为block;