仿新浪下拉菜单css+html+js代码效果图:
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
list-style: none;
}
.nav {
margin:100px;
}
.nav>li {
position: relative;
float: left;
width:80px;
height:41px;
text-align: center;
}
.nav li a {
display: block;
height:100%;
width:100%;
text-decoration: none;
line-height:41px;
color: #333;
}
.nav>li>a:hover {
background-color: #eee;
}
.nav ul {
display: none;
position: absolute;
position: absolute;
top:41px;
left:0;
width:100%;
border-left:1px solid #FECC5B;
border-right:1px solid #FECC5B;
}
.nav ul li {
border-bottom:1px solid #FECC5B;
}
.nav ul li:hover {
background-color: #FFF5DA;
}
</style>
</head>
<body>
<ul class="nav">
<li>
<a href="#">微博</a>
<ul>
<li><a href="#">私信</a></li>
<li><a href="#">评论</a></li>
<li><a href="#">@我</a></li>
</ul>
</li>
<li>
<a href="#">博客</a>
<ul>
<li><a href="#">私信</a></li>
<li><a href="#">评论</a></li>
<li><a href="#">@我</a></li>
</ul>
</li>
<li>
<a href="#">邮箱</a>
<ul>
<li><a href="#">私信</a></li>
<li><a href="#">评论</a></li>
<li><a href="#">@我</a></li>
</ul>
</li>
</ul>
<script>
//1、获取元素
var nav = document.querySelector('.nav');
var lis = nav.children;//得到四个li
//2、循环注册事件
for(var i =0; i < lis.length; i++){
lis[i].onmouseover=function(){
this.children[1].style.display ='block';
html下拉菜单的制作方法}
lis[i].onmouseout=function(){
this.children[1].style.display ='none';
}
}
</script>
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论