<ul id="nav">
<li><a href="<?url ctrl=home?>">首 頁</a></li>
<li><a href="#">|</a></li>
<li><a href="#">關于我們</a>
<!-- 下拉部分-->
<ul><li><a href="#">公司簡介</a></li>
<li><a href="#">總經(jīng)理致辭</a></li>
</ul></li>
<!-- 下拉部分-->
</ul>
js就幾行代碼:
<script type=text/javascript><!--//--><![CDATA[//><!--
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>
css代碼:
#nav {
line-height: 24px; list-style-type: none;
}
#nav a {
display: block; text-align:center;
}
#nav a:link {
color:#a6ce38; text-decoration:none;
}
#nav a:visited {
color:#a6ce38;text-decoration:none;
}
#nav a:hover {
color:#F00; text-decoration:none;;
}
#nav li {
float: left; padding-left:15px; font-family:"微軟雅黑"; font-size:14px;
}
#nav li a:hover{
color:#F00;
}
#nav li ul {
line-height:18px; list-style-type: none;text-align:left;
left: -999em; width:120px; position: absolute;
}
#nav li ul li{
background: #FFF;/*沒有背景在ie6下會有一點小問題*/
float:left; width:100px;
font-family:"微軟雅黑"; font-size:12px; color:#F00;
margin:0px;padding:0;
clear:both;
}
#nav li ul a{
display: block; width:100px;text-align:left;
}
#nav li ul a:link {
color:#a6ce38; text-decoration:none;
}
#nav li ul a:visited {
color:#a6ce38; text-decoration:none;
}
#nav li ul a:hover {
color:#FFF; text-decoration:none;
background:#F00;
}
#nav li:hover ul {
left: auto;
}
#nav li.sfhover ul {
left: auto;
}