网页代码库


简洁的双级导航菜单

看看效果 2008.10.15

xhtml部分

<ul id="butong-nav">
	<li><a href="#">Home</a></li>
	<li><a href="#">About</a>
		<ul>
			<li><a href="#">History</a></li>
			<li><a href="#">Team</a></li>
			<li><a href="#">Offices</a></li>
		</ul>
	</li>
	<li><a href="#">Services</a>
		<ul>
			<li><a href="#">Web Design</a></li>
			<li><a href="#">Internet Marketing</a></li>
			<li><a href="#">Hosting</a></li>
			<li><a href="#">Domain Names</a></li>
			<li><a href="#">Broadband</a></li>
		</ul>
	</li>
	<li><a href="#">Contact Us</a>
		<ul>
			<li><a href="#">United Kingdom</a></li>
			<li><a href="#">France</a></li>
			<li><a href="#">USA</a></li>
			<li><a href="#">Australia</a></li>
		</ul>
	</li>
</ul>

css部分

#butong-nav, #butong-nav ul {
	font: normal 11px verdana;
	margin: 0;
	padding: 0;
	list-style: none;
	width: 150px;
	border-bottom: 1px solid #CCC;
 }
  
#butong-nav li {
	position: relative;
}
  
#butong-nav ul {
	position: absolute;
	left: 149px;
	top: 0;
	display: none;
}
#butong-nav li a {
	display: block;
	text-decoration: none;
	color: #777;
	background: #fff;
	padding: 5px;
	border: 1px solid #ccc;
	border-bottom: 0;
}
#butong-nav li a:hover {
	text-decoration: underline;
}
* html #butong-nav li {
	float: left;
	height: 1%;
}
* html #butong-nav li a {
	height: 1%;
}
#butong-nav li:hover ul, #butong-nav li.over ul {
	display: block;
}

JavaScript部分

startList = function() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("butong-nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI") {
				node.onmouseover = function() {
					this.className += "over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace("over", "");
				}
			}
		}
	}
}
window.onload = startList;

关于我

站长:皮成,致力于web前端技术。

网站:收集以web前端技术实现的网页实例,探讨网页实例背后的web前端技术。

Email:Strict.dtd[at]Gmail.com QQ:52541666