一个简单的DIV+CSS做的导航菜单

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>UL LI结构实现二级导航菜单(HTML+CSS+JS)</title>
<style type="text/css">
*{margin:0;padding:0;border:0;}

body {
font-family: arial, 微软雅黑, serif;
font-size:16px;
}

#nav {
line-height:40px; list-style-type: none; background:#666;
}

#nav a {
display: block; width: 120px; text-align:center;
}

#nav a:link {
color:#666; text-decoration:none;
}

#nav a:visited {
color:#666;text-decoration:none;
}

#nav a:hover {
color:#FFF;text-decoration:none;font-weight:bold;
}

#nav li {
float: left; width: 120px; background:#CCC;
flex:1;

}

#nav li a:hover{
background:#999;
}

#nav li ul {
line-height: 40px; list-style-type: none;text-align:left;
left: -999em; width: 120px; position: absolute;
}

#nav li ul li{
float: left; width: 180px;
background: #F6F6F6;
}

#nav li ul a{
display: block; width: 165px;_width: 180px;height:auto; margin:0 auto;text-align:left; padding-left:15px;
}

#nav li ul a:link {
color:#666; text-decoration:none;
}
#nav li ul a:visited {
color:#666;text-decoration:none;
}
#nav li ul a:hover {
color:#F3F3F3;text-decoration:none;font-weight:normal;
background:#C00;
}

#nav li:hover ul {
left: auto;
}
#nav li.sfhover ul {
left: auto;
}
#content {
clear: left;
}
</style>

<script type=text/javascript>
function menuFix() {
var sfEls = document.getElementById("nav").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=(this.className.length>0? " ": "") + "sfhover";
}
sfEls[i].onMouseDown=function() {
this.className+=(this.className.length>0? " ": "") + "sfhover";
}
sfEls[i].onMouseUp=function() {
this.className+=(this.className.length>0? " ": "") + "sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"),

"");
}
}
}
window.onload=menuFix;

</script>

</head>
<body>

<ul id="nav">
<li>a href="http://www.51xuediannao.com">懒人建站</a>
<ul>
<li><a href="http://www.51xuediannao.com/JS/nav/">CSS导航菜单</a></li>
<li><a href="http://www.51xuediannao.com/JS/Slide/">FLASH焦点图</a></li>
<li><a href="http://www.51xuediannao.com/JS/texiao/">网页特效JS</a></li>
<li><a href="http://www.51xuediannao.com/JS/AD/">JS广告代码</a></li>
</ul>
</li>
<li><a href="http://www.51xuediannao.com/show">欣赏借鉴</a>
<ul>
<li><a href="http://www.51xuediannao.com/show/qiye/">企业类网站</a></li>
<li><a href="http://www.51xuediannao.com/show/hangye/">行业类网站</a></li>
<li><a href="http://www.51xuediannao.com/show/blog/">BLOG类网站</a></li>
<li><a href="http://www.51xuediannao.com/show/menhu/">门户类网站</a></li>
<li><a href="http://www.51xuediannao.com/show/shop/">商城类网站</a></li>
</ul>
</li>
<li><a href="http://www.51xuediannao.com/jiqiao/">建站技巧</a>
<ul>
<li><a href="http://www.51xuediannao.com/jiqiao/html/">HTML技巧</a></li>
<li><a href="http://www.51xuediannao.com/jiqiao/css/">CSS技巧</a></li>
<li><a href="http://www.51xuediannao.com/jiqiao/cms/">CMS建站技巧</a></li>
<li><a href="http://www.51xuediannao.com/jiqiao/qita/">其他技巧</a></li>
</ul>
</li>
<li><a href="http://51xuediannao.com">懒人建站</a>
<ul>
<li><a href="http://www.51xuediannao.com/JS/nav/">CSS导航菜单</a></li>
<li><a href="http://www.51xuediannao.com/JS/Slide/">FLASH焦点图</a></li>
<li><a href="http://www.51xuediannao.com/JS/texiao/">网页特效JS</a></li>
<li><a href="http://www.51xuediannao.com/JS/AD/">JS广告代码</a></li>
</ul>
</li>

<li><a href="#">在线演示</a>
<ul>
<li><a href="http://51xuediannao.com/JS/nav/">CSS导航菜单</a></li>
<li><a href="http://51xuediannao.com/JS/Slide/">FLASH焦点图</a></li>
<li><a href="http://51xuediannao.com/JS/texiao/">网页特效JS</a></li>
<li><a href="http://51xuediannao.com/JS/AD/">JS广告代码</a></li>
</ul>
</li>
<li><a href="http://51xuediannao.com/jiqiao/">建站技巧</a>
<ul>
<li><a href="http://51xuediannao.com/jiqiao/html/">HTML技巧</a></li>
<li><a href="http://51xuediannao.com/jiqiao/css/">CSS技巧</a></li>
<li><a href="http://51xuediannao.com/jiqiao/cms/">CMS建站技巧</a></li>
<li><a href="http://51xuediannao.com/jiqiao/qita/">其他技巧</a></li>
</ul>
</li>
</ul>

<!--下面只是说明与程序代码无关-->
<br>
<div style="width:95%; height:auto; display:block; margin:0 auto; margin-top:30px; font-size:10pt; line-height:150%;">
<span>懒人建站为您提供-各种bolg制作技巧,HTML技巧,CSS技巧和CMS使用技巧</span><br />
<span>懒人建站只收录实用和能提高用户体验的代码</span><br />
<span>我们只想解放出你的部分写代码时间来思考更高层次的设计,而不是要你懒惰、拼凑。</span>
</div>

</body>
</html>
本文章由 brokenway 发布在 个人知识库 ,文章所述不代表本站观点,法律风险由发布者自行承担,转载请注明出处!