CSS菜单.html 文件代码清单如下:
<!doctype html><html langj="zh">
<head>
<meta charset="utf-8">
<title>CSS菜单</title>
<link rel="stylesheet" href="cssmenu.css">
</head>
<body>
<ul>
<li><a href="">A</a></li>
<li><a href="">B</a>
<ul>
<li><a href="">B1</a></li>
<li><a href="">B2</a></li>
<li><a href="">B3</a></li>
</ul>
</li>
<li><a href="">C</a>
<ul>
<li><a href="">C1</a></li>
<li><a href="">C2</a></li>
<li><a href="">C3</a></li>
</ul>
</li>
<li><a href="">D</li>
</ul>
</body>
</html>
cssmenu.css 文件代码清单如下:
/* cssmenu.css */ul li, ul li:hover ul {
display: block
}
ul li ul {
display: none
}
<div class="menu"><ul>
<li><a class="hide" href="index.html">首页</a></li>
<li><a class="hide" href="page.html">关于我们</a>
<ul>
<li><a href="page.html">关于合作建房</a></li>
<li><a href="page.html">企业文化</a></li>
<li><a href="page.html">企业荣誉</a></li>
<li><a href="page.html">核心理念</a></li>
</ul>
</li>
<li><a class="hide" href="#">合作成功密码</a>
<ul>
<li><a href="page.html">合作模式</a></li>
<li><a href="page.html">加入流程</a></li>
<li><a href="#">团购幸福家</a></li>
<!--链接页面待定,先链接到page03.html-->
</ul>
</li>
<li><a class="hide" href="#">案例参考</a>
<ul>
<li><a href="page.html">成功案例</a></li>
<li><a href="page.html">失败案例</a></li>
<li><a href="page.html">国外案例</a></li>
</ul>
</li>
<li><a class="hide" href="#">区域项目简介</a>
<ul>
<li><a href="page02.html">华南(国际)口腔医疗器械城</a></li>
<li><a href="page02.html">华南(国际)医疗器材产业中心</a></li>
<li><a href="page02.html">清远红场大型购物商场</a></li>
<li><a href="page02.html">佛山鸿业幼儿园</a></li>
<li><a href="page02.html">佛山西樵金果广场</a></li>
<li><a href="page02.html">佛山石湾行政服务中心</a></li>
</ul>
</li>
<li><a class="hide" href="reg.html">我要报名</a> </li>
<li><a class="hide" href="news-list.html">法律保障</a> </li>
<li><a class="hide" href="page.html">联系我们</a> </li>
</ul>
<div class="clear"> </div>
</div> .menu {
font-family: arial, sans-serif
width: 1000px
height: 38px
margin-top: 5px
position:relative
z-index:10
}
.menu ul {
padding: 0
margin: 0
list-style-type: none
position:relative
z-index:10
}
.menu ul li {
width: 125px
height: 38px
float: left
position: relative
background: url(../images/index_09.jpg) no-repeat left
position:relative
z-index:10
}
.menu ul li a {
display: block
text-align: center
text-decoration: none
display: block
height: 38px
color: #bfd9eb
line-height: 33px
font-size: 14px
font-weight: bold
position:relative
z-index:10
}
.menu ul li a:visited {
display: block
text-align: center
text-decoration: none
width: 125px
display: block
height: 38px
line-height: 38px
font-size: 14px
font-weight: bold
position:relative
z-index:10
}
.menu ul li ul {
display: none
position:relative
z-index:10
}
.menu ul li:hover a {
color: #000
background: #fff
border: none
position:relative
z-index:10
}
.menu ul li:hover ul {
display: block
position: absolute
top: 35px
left: 0
border-top: none
}
.menu ul li:hover ul li a {
display: block
background: #fff
color: #000
font-size: 12px
font-weight: normal
text-align: left
padding-left: 10px
border: none
}
.menu ul li:hover ul li a:hover {
background: #008fc3
color: #f00
}
利用伪类可以实现点击打开折叠菜单,但是再次点击收起貌似就没法实现了。跟楼下说的一样,利用:hover、:active 可以设置二级菜单的样式(如height、visibility、display)以达到展开的效果。