css简单下拉效果实现

Original 2019-01-30 13:56:47 263
abstract:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>淘宝布局</title><html lang="en"><head><meta charset="

<!DOCTYPE html>

<html lang="en">


<head>

<meta charset="UTF-8">

<title>淘宝布局</title>



<html lang="en">




<head>


<meta charset="UTF-8">


<title>淘宝布局</title>


<link rel="stylesheet" href="staic/css/font-awesome-4.7.0/font-awesome-4.7.0/css/font-awesome.min.css">


<style>

* {


margin: 0;


padding: 0;


}




a {


text-decoration: none;


color: #3C3C3C;


font-size: 12px;


}

li{

list-style: none;

}



.clear {


clear: both;


}




.header {


width: 100%;


background-color: #f5f5f5;


}




.header_content {


width: 1197px;


margin: 0 auto;


line-height: 35px;


}




.header_left {




height: 35px;


float: left;


}




.header_right {


height: 35px;


float: right;


}




.header_a {


display: inline-block;


width: 90px;


height: 35px;


text-align: center;


}




.header_a {


display: inline-block;


width: 90px;


height: 35px;


text-align: center;


}




.header_a:hover {


display: inline-block;


width: 90px;


height: 35px;


text-align: center;


background-color: #fff;

position: relative;


}






.header a {


margin-right: 5px;


}




.header a:hover {


color: #f22e00 !important;


}


.header_a ul{

border: 1px solid #f5f5f5;

display: none;

position: absolute;

width: 100px;

border-top:none;

}

.header_a:hover ul{

display: block;

}

.header_a ul li{

color: #6c6c6c;

height: 30px;

line-height: 30px;

text-align: left;

padding: 0 3px;

}

.header_a ul li:hover{

background-color: #f5f5f5;

}



</style>




</head>




<body>


<div class="header">


<div class="header_content">


<div class="header_left">


<a href="" class="header_a">中国大陆&nbsp;<i class="fa fa-angle-down"></i></a>


<a href="" style="color: #f22e00">亲,请登录</a>


<a href="">免费注册</a>


<a href="">手机逛淘宝</a>


</div>


<div class="header_right">


<a href="" class="header_a">我的淘宝&nbsp;<i class="fa fa-angle-down"></i>

<ul>

<li>已买到的宝贝</li>

<li>足迹</li>

</ul>

</a>


<a href="" class="header_a"><i class="fa fa-shopping-cart"></i>&nbsp;购物车&nbsp;<i class="fa fa-angle-down"></i></a>


<a href=""><i class="fa fa-star"></i>&nbsp;收藏夹</a>


<a href="">商品分类</a>


<a href="" class="header_a">卖家中心&nbsp;<i class="fa fa-angle-down"></i>

<ul>

<li>免费开店</li>

<li>已卖出的宝贝</li>

<li>已买到的宝贝</li>

</ul>

</a>


<a href="" class="header_a">联系客服&nbsp;<i class="fa fa-angle-down"></i>

<ul>

<li>消费者客服</li>

<li>卖家客服</li>

</ul>

</a>


<a href="">网站导航</a>




</div>


</div>


<div class="clear"></div>


</div>




</body>




</html>

总结:实现下拉的原理即改变下拉部分的display属性,另在下拉ul的父级元素设置一个相对定位,在给ul一个绝对定位可以让ul排版正确而不会挤掉后面的元素


Correcting teacher:韦小宝Correction time:2019-01-31 09:15:07
Teacher's summary:写的很不错 css实现下拉效果还是比较简单的 课后记得要多练习哦 继续加油吧

Release Notes

Popular Entries