html css二级导航栏

 二级导航栏制作:

1.将一级导航栏去除列表样式(list-style:none),并给予浮动,使其横向排列(float:left)

2.给每个li中添加一个<a></a>标签,给a设置样式,使其成为块级元素( display:block),这样只需要点击当前 li 范围区域即可触发a的跳转

3.给需要添加二级导航栏的li里面添加 ul>li ,给个类名,设置其样式为(display:none),使其在普通情况下隐藏

4.设置一级导航栏划过效果,当滑到有二级导航栏的 li 时,设置二级导航栏状态为(display:block),即为显示状态

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <link rel="stylesheet" href="./../common/common.css"> -->
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul,li{
            list-style: none;
        }
        .one{
            width: 600px;
            background-color: coral;
            height: 30px;
            margin: 0 auto;
        }
        .one li{
            float: left;
            width: 100px;
            text-align: center;
            line-height: 30px;
        }
        .one li:hover{
            background-color: #fff;
            color: coral;
        }
        .one .two{
            display: none;
        }
        .one li:hover .two{
            display: block;
        }
        .one .two li{
            background-color: cadetblue;
        }

        .one .two li:hover{
            background-color: honeydew;
        }
        a{
            display: block;
            text-decoration: none;
        }
    </style>
</head>
<body>
    
    <ul class="one">
        <li><a href="">一级</a> </li>
        <li><a href="">一级</a> </li>
        <li><a href="">一级</a>
            <ul class="two">
                <li><a href="">二级</a> </li>
                <li><a href="">二级</a> </li>
                <li><a href="">二级</a> </li>
            </ul>
        </li>
        <li><a href="">一级</a> </li>
        <li><a href="">一级</a> </li>
        <li><a href="">一级</a> </li>
    </ul>

</body>
</html>

  

posted @ 2020-02-23 19:29  fjxylin  阅读(3484)  评论(0编辑  收藏  举报