简单下拉菜单案列

原创 2019-02-18 21:19:39 292
摘要:<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>淘寶頂部導航條</title
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>淘寶頂部導航條</title>
    <link rel="stylesheet" type="text/css" href="../css/index.css">
    <link rel="stylesheet" type="text/css" href="../css/font-awesome-4.7.0/css/font-awesome.min.css">
</head>
<body>
<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: orange">親,親登錄</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="#"><span class="fa fa-shopping-cart"></span> 购物车&nbsp;<i class="fa fa-angle-down"></i></a>
            <a href="#" class="header-a"><span class="fa fa-star"></span> 收藏夹&nbsp;<i class="fa fa-angle-down"></i></a>
            <a href="#">商品分类</a>&nbsp;|
 <a href="#" class="header-a">卖家中心&nbsp;<i class="fa fa-angle-down"></i></a>
            <a href="#" class="header-a">联系客服&nbsp;<i class="fa fa-angle-down"></i></a>
            <a href="#" class="header-a"><i></i>网站导航&nbsp;<i class="fa fa-angle-down"></i></a>
        </div>
        <div class="clear"></div>
    </div>
</header>
</body>
</html>

样式

*{margin: 0;padding: 0;}
a{text-decoration: none;color: #0f0f0f;font-size: 13px;}
li{list-style: none;}
.clear{clear: both;}
header{
    width: 100%;/*height: 40px;*/
    background-color: #F5F5F5;
}
.header-content{
    width:1200px;
    /*height: 40px;*/
    margin: 0 auto;
    line-height: 40px;
}
.header-content a:hover{
    color:orange;
}
.header-left{
    height: 40px;
    float: left;
}
.header-left a{
    margin-right: 5px;
}
.header-a{
    display: inline-block;
    position: relative;
    width: 90px;height: 40px;
    text-align: center;
}
.header-a:hover{
    background-color: white;
}
.header-a ul{
    position: absolute;
    display: none;
    width: 100px;
    padding: 5px 0px;
    border:1px solid #F5F5F5;
    border-top: none;
}
.header-a:hover ul{display: block;}
.header-a ul li{
    color: #6c6c6c;
    height: 30px;line-height: 30px; text-align: left;
    padding: 0px 3px;
}
.header-a ul li:hover{background-color: #F5F5F5}
.header-right{
    height: 40px;
    float: right;
}
.header-right .fa-shopping-cart{
    color: orange;
}

总结:

导航是用a标签,下拉菜单用的ul li 。因为用到下拉菜单都是用的ul li,就可以给ul li设样式 或 给 ul li一个相同的类来 实现样式复用

需要注意:a标签里面放ul会把 导航栏后面节内容挤到下面去。给导航栏a标签一个相对定位,再给ul一个绝对定位就能都解决。

下拉框大小可以设置ul的大小。如果要个全导航栏的下拉框,把ul的宽度设为导航条的宽度,再用定位定好位置就可以了。

效果图

one.gif

批改老师:韦小宝批改时间:2019-02-19 09:12:52
老师总结:写的很不错 总结的也没毛病 代码写的也很规范 继续加油吧!

发布手记

热门词条