效果图
鼠标放置时
文件
代码
素材
网页架构
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>传智商城下拉菜单</title>
<link rel="stylesheet" href="example24.css" type="text/css">
<script type="text/javascript" src="example24.js"></script>
</head>
<body>
<div id="top">
<ul class="top_nav">
<ul>
<li>亲,请登录</li>
<li>免费注册</li>
</ul>
<ul class="right">
<li class="u100" onmouseover="change('u101','block')" onmouseout="change('u101','none')">
<span>我的商城</span>
<div id="u101">
<a>已买到的宝贝</a>
<a>我的足迹</a>
<a>我的上新</a>
<a>爱逛街</a>
<a>商城达人</a>
<a>新欢</a>
</div>
</li>
<li class="line">|</li>
<li><span>购物车</span></li>
<li class="line">|</li>
<li><span>收藏夹</span></li>
<li class="line">|</li>
<li><span>卖家中心</span></li>
<li class="line">|</li>
<li><span>联系客服</span></li>
</ul>
</ul>
</div>
<div id="header">
<a class="left"><img src="images/logo.png"></a>
<div id="search" class="left">
<input type="text" class="left">
<input class="search_btn" type="button" value="搜索">
<p>热门搜索: 网页培训 大学教材 智能手机 平板电脑</p>
</div>
<div id="info" class="left">
<input type="button" value="会员中心">
<input type="button" value="去购物车结算">
</div>
</div>
</body>
</html>
CSS央样式
body,ul,input,p,dl,dt,dd,h1{margin: 0;padding: 0;}
body{min-width: 755px;color: #6c6c6c;font-size: 12px;}
ul{
list-style: none;
}
a{
text-decoration: none;
}
a:hover{
text-decoration: none;
}
.left{
float: left;
}
.right{
float: right;
}
/*下拉菜单*/
.right .u100{position: relative;}
.right #u101{
width: 95px;
display: none;
position: absolute;
left: 0;
top: 30px;
background-color: #fff;
border: thin;
border-color: #eee;
}
.right #u101 a{
display: block;
padding: 0 10px;
line-height: 28px;
color: #6c6c6c;
}
.right #u101 a:hover{
background: #f5f5f5;
}
/*用户信息栏*/
#top{
height: 30px;
line-height: 30px;
background: #f7f7f7;
border-bottom: 1px solid #eee;
}
#top ul{
margin: 0 20px;
}
#top li{
float: left;
padding: 0px 5px 0px 0px;
}
#top .line{
color: #ccc;
}
#top .top_nav{
max-width: 1220px;
margin: 0 auto;
}
.right li{
cursor: pointer;
}
.right li span{
padding: 0px 9px;
}
/*头部*/
#header{
width: 1220px;
margin: 0 auto;
padding-top: 20px;
overflow: hidden;
}
#header a{
width: 240px;
display: block;
}
#header #search{
width: 500px;
margin-top: 15px;
}
#header #search input{
width: 416px;
height: 30px;
border: 3px solid #e4393c;
}
#header #search .search_btn{
width: 78px;
height: 36px;
background: #e4393c;
font-size: 14px;
font-weight: 700;
color: #fff;
cursor: pointer;
}
#header #search p{
color: #999;
font-size: 12px;
margin-top: 5px;
}
#header #info{
margin-top: 18px;
margin-left: 20px;
}
#header #info input{
height: 32px;
border: 1px solid #e3e3e3;
background-color: #f7f7f7;
color: #666;
padding: 0 10px;
margin-left: 12px;
}
JS代码
function change(myid,mode) {
document.getElementById(myid).style.display=mode;
if(mode=='block'){//显示下拉菜单
//设置下拉菜单所在的div边框
document.getElementById(myid).style.border="1px solid #eee";
document.getElementById(myid).style.borderTop="none";
//设置鼠标划过的li的边框以及背景颜色
document.getElementById(myid).parentNode.style.backgroundColor="#fff";
document.getElementById(myid).parentNode.style.border="1px solid #eee";
document.getElementById(myid).parentNode.style.borderBottom="none";
}
else{
//当不显示下拉列表的时候 鼠标划过的li的边框以及背景颜色
document.getElementById(myid).parentNode.style.backgroundColor="";
document.getElementById(myid).parentNode.style.border="";
}
}