css结合js制作下拉菜单示例代码

时间:2021-05-26

复制代码 代码如下:
<%@page pageEncoding="utf-8"
contentType="text/html;charset=utf-8" %>

<HTML>
<HEAD>
<title>WebForm5</title>

<style>
ul#navmenu-h {
margin: 0;
border: 0 none;
padding: 0;
width: 500px;
list-style: none;
height: 24px;
}

ul#navmenu-h li {
margin: 0;
border: 0 none;
padding: 0;
float: left;
display: inline;
list-style: none;
position: relative;
height: 24px;
}

ul#navmenu-h ul {
margin: 0;
border: 0 none;
padding: 0;
width: 160px;
list-style: none;
display: none;
position: absolute;
top: 24px;
left: 0;
}

ul#navmenu-h ul:after {
clear: both;
display: block;
font: 1px/0px serif;
content: ".";
height: 0;
visibility: hidden;
}

ul#navmenu-h ul li {
width: 160px;
float: left;
display: block !important;
display: inline;
}


ul#navmenu-h a {
border: 1px solid #FFF;
border-right-color: #CCC;
border-bottom-color: #CCC;
padding: 0 6px;
float: none !important;
float: left;
display: block;
background: #EEE;
color: #666;
font: bold 10px/22px Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
height: auto !important;
height: 1%;
}


ul#navmenu-h a:hover,
ul#navmenu-h li:hover a,
ul#navmenu-h li.iehover a {
background: #CCC;
color: #FFF;
}


ul#navmenu-h li:hover li a,
ul#navmenu-h li.iehover li a {
float: none;
background: #EEE;
color: #666;
}


ul#navmenu-h li:hover li a:hover,
ul#navmenu-h li:hover li:hover a,
ul#navmenu-h li.iehover li a:hover,
ul#navmenu-h li.iehover li.iehover a {
background: #CCC;
color: #FFF;
}


ul#navmenu-h li:hover li:hover li a,
ul#navmenu-h li.iehover li.iehover li a {
background: #EEE;
color: #666;
}


ul#navmenu-h li:hover li:hover li a:hover,
ul#navmenu-h li:hover li:hover li:hover a,
ul#navmenu-h li.iehover li.iehover li a:hover,
ul#navmenu-h li.iehover li.iehover li.iehover a {
background: #CCC;
color: #FFF;
}


ul#navmenu-h li:hover li:hover li:hover li a,
ul#navmenu-h li.iehover li.iehover li.iehover li a {
background: #EEE;
color: #666;
}


ul#navmenu-h li:hover li:hover li:hover li a:hover,
ul#navmenu-h li.iehover li.iehover li.iehover li a:hover {
background: #CCC;
color: #FFF;
}

ul#navmenu-h ul ul,
ul#navmenu-h ul ul ul {
display: none;
position: absolute;
top: 0;
left: 160px;
}


ul#navmenu-h li:hover ul ul,
ul#navmenu-h li:hover ul ul ul,
ul#navmenu-h li.iehover ul ul,
ul#navmenu-h li.iehover ul ul ul {
display: none;
}

ul#navmenu-h li:hover ul,
ul#navmenu-h ul li:hover ul,
ul#navmenu-h ul ul li:hover ul,
ul#navmenu-h li.iehover ul,
ul#navmenu-h ul li.iehover ul,
ul#navmenu-h ul ul li.iehover ul {
display: block;
}

</style><script language="javascript">
navHover = function() {
var lis = document.getElementById("navmenu-h").getElementsByTagName("LI");
for (var i=0; i<lis.length; i++) {
lis[i].onmouseover=function() {
this.className+=" iehover";
}
lis[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" iehover\\b"),

"");
}
}
}
if (window.attachEvent) window.attachEvent("onload", navHover);
</script>
</HEAD>
<body>
<ul id="navmenu-h">
<li><a href="#">Root nav item1</a>
<ul>
<li><a href="#">Sub nav item1</a></li>
<li><a href="#">Sub nav item1-2</a></li>
</ul>
</li>
<li><a href="#">Root nav item2</a>
<ul>
<li><a href="#">Sub nav item2</a></li>
<li><a href="#">Sub nav item2-2</a></li>
</ul>
</li>
<li><a href="#">Root nav item3</a>
<ul>
<li><a href="#">Sub nav item3</a></li>
<li><a href="#">Sub nav item3-2</a></li>
</ul>
</li>
</ul>
</body>
</html>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章