定位练习
定位练习简易二级菜单栏
原图效果:
要求:实现二级菜单栏效果
代码实现:
html部分:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>作业01</title>
<link rel="stylesheet" type="text/css" href="css/01.css" />
</head>
<body>
<div class="header">
<div class="box-div">
<ul class="box-ul">
<li class="box-li">
<a href="#">你好,请登录</a>
</li>
<li class="box-li">
<a href="#">免费注册</a>
</li>
<li class="w1"></li>
<li class="box-li">
<a href="#">我的订单</a>
</li>
<li class="w1"></li>
<li class="box-li box-li1">
<a href="#">我的京东</a>
<div class="box-xl">
<div class="box-xl-a1">
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
</div>
<div class="box-xl-a2">
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
</div>
</div>
</li>
<li class="w1"></li>
<li class="box-li">
<a href="#">京东会员</a>
</li>
<li class="w1"></li>
<li class="box-li box-li1">
<a href="#">企业采购</a>
<div class="box-xl box-xl-2">
<div class="box-xl-a2">
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
</div>
</div>
</li>
<li class="w1"></li>
<li class="box-li box-li1">
<a href="#">客户服务</a>
<div class="box-xl box-xl-3">
<div class="box-xl-a1 box-xl-b1">
<p>客户</p>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
<a href="#" class="a1">我的京东1</a>
</div>
<div class="box-xl-a2">
<p>商户</p>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
<a href="#" class="a1">我的京东2</a>
</div>
</div>
</li>
<li class="w1"></li>
<li class="box-li box-li1">
<a href="#">网站导航</a>
<div class="box-xl-end">
<div class="box-xl-enda1"></div>
<div class="box-xl-enda1"></div>
<div class="box-xl-enda1"></div>
<div class="box-xl-enda1"></div>
</div>
</li>
<li class="w1"></li>
<li class="box-li">
<a href="#">手机京东</a>
</li>
</ul>
</div>
</div>
</body>
</html>
css部分:
*{
margin:0;
padding:0;
font-family:"微软雅黑";
}
a {
text-decoration:none;
color:#999;
}
ul,ol{
list-style:none;
}
.clearFloat:after{
clear:both;
content:"";
display:block;
}
.header{
width:100%;
height:30px;
margin:50px auto 0;
border-bottom:solid 1px #ddd;
background:#e3e4e5;
}
.box-div{
width:1190px;
height:30px;
margin:0 auto;
}
li{
float:left;
position:relative;
}
.w1{
width:1px;
height:10px;
background:#ccc;
margin:11px 5px 0;
overflow:hidden;
}
.box-ul{
width:850px;
height:30px;
line-height:30px;
float:right;
position:relative;
}
.box-li{
padding:0 7px;
height:29px;
border-top:solid 1px #e3e4e5;
border-right:solid 1px #e3e4e5;
border-left:solid 1px #e3e4e5;
border-bottom:solid 1px #ddd;
}
.box-li1:hover{
border-top:solid 1px #ccc;
border-right:solid 1px #ccc;
border-left:solid 1px #ccc;
border-bottom:solid 1px #fff;
background:#fff;
}
.box-xl{
width:280px;
height:200px;
background:#fff;
border:solid 1px #ccc;
box-shadow:1px 2px 1px rgba(0,0,0,0.1);
position:absolute;
top:30px;
left:0;
display:none;
}
.box-xl-a1{
width:280px;
height:120px;
float:left;
border-bottom:solid 1px #ccc;
}
.a1{
display:inline-block;
float:left;
width:100px;
height:35px;
line-height:40px;
text-align:center;
}
.a1:hover{
color:red;
}
.box-li:hover .box-xl,.box-xl-end{
display:block;
}
.box-li:hover .box-xl-end{
display:block;
}
.box-xl-2{
width:200px;
height:90px;
}
.box-xl-3{
width:200px;
height:350px;
}
.box-xl-b1{
width:200px;
height:210px;
}
.box-xl-end{
width:1188px;
height:350px;
right:-84px;
background:#fff;
border:solid 1px #ccc;
box-shadow:1px 2px 1px rgba(0,0,0,0.1);
position:absolute;
top:30px;
display:none;
}
.box-xl-enda1{
width:290px;
height:320px;
float:left;
border-right:solid 1px #ccc;
margin-top:15px;
}
.box-xl-enda1:last-child{
border:0;
}
实现效果:
总结:
这里需要熟练掌握并使用 相对定位 (position:relative;
) 绝对定位(position:absolute;
) hover伪类 diaplay:none/display:block
需要多加练习。