纯HTML+CSS实战之实现带图标的二级导航菜单

效果图如上

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>纯CSS实现带图标的二级导航菜单</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            border: none;
            outline: none;
        }
        .menu{
            width: 600px;
            height: 60px;
            /*背景渐变颜色*/
            background: linear-gradient(to bottom,#4c4e4a 0%,#2c2d33 100%);
            /*圆角边框*/
            border-radius: 5px;
            margin: 100px auto;
        }
        .menu li{
            list-style: none;
            position: relative;
            float: left;
            height: 60px;
            line-height: 60px;
            text-align: center;
        }
        .menu li:hover >a{
            color: #2ec200;
        }
        .menu li>a{
            display: inline-block;
            padding: 0 24px;
            margin: 6px 0;
            line-height: 28px;
            text-decoration: none;
            color: white;
            border-left: 2px solid #93939d;
            /*基础的文本阴影效果*/
            text-shadow: 1px 1px 1px rgba(0,0,0,6);
        }
        .menu>li:nth-child(1) a{
            border-left: none;
            margin-left: 17px;
        }

        /*下面写二级菜单样式*/
        .menu ul{
            position: absolute;
            top: 60px;
            left: 0;
            /*opacity 设置元素的不透明级别*/
            opacity: 0;
            background-color: #4c4e4a;
            border-radius: 0 0 5px 5px;
            transition: opacity 500ms ease 1ms;
        }
        .menu li:hover >ul{
            opacity: 1;
        }
        .menu ul li{
            height: 0;
            overflow: hidden;
            padding: 0;
            transition: height 500ms ease 1ms;
            position: relative;
        }
        .menu li:hover >ul li{
            height: 60px;
            overflow: visible;
        }
        .menu ul li a{
            font-size: 13px;
            padding: 14px 20px 14px 40px;
            border-left: none;
            border-bottom: 1px solid #0cf;
        }
        .menu ul li:last-child a{
            border: none;
        }
        .menu div{
            position: absolute;
            left: 18px;
            top: 26px;
            width: 13px;
            height: 13px;
            display: inline-block;
        }
        .menu .b1{
            background: url("images/5652/27.png") no-repeat center center;
        }
        .menu .b2{
            background: url("images/5652/26.png") no-repeat center center;
        }
        .menu .b3{
            background: url("images/5652/28.png") no-repeat center center;
        }
    </style>
</head>
<body>
<ul class="menu">
    <li><a href="#">首页</a></li>
    <li><a href="#">一级菜单</a></li>
    <li><a href="#">带二级菜单</a>
        <ul>
            <li>
                <div class="b1"></div>
                <a href="#">二级菜单01</a></li>
            <li>
                <div class="b2"></div>
                <a href="#">二级菜单02</a>
            </li>
            <li><div class="b3"></div>
                <a href="#">二级菜单03</a>
            </li>
        </ul>
    </li>
    <li><a href="#">带二级菜单</a></li>
    <li><a href="#">一级菜单</a></li>
</ul>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_41886761/article/details/86355163