css实现动态二级菜单

码农公社  210.net.cn   210是何含义?10月24日是程序员节,1024 = 210、210既 210 之意。


动态实现简单的二级菜单


2073818-20200629200959095-372978316.jpg



当鼠标放到一级标签上时,鼠标会变成小手的形状 展示二级菜单,源码如下,复制即可直接使用



<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {margin: 0; padding: 0;}
        ul { list-style: none;}
        div {
            width: 100%;
            height: 50px;
            background-color: #ccc;
        }
        .first {
            width: 100px;
            height: 50px;
            float: left;
            margin-right: 70px;
            /* background-color: pink; */
            cursor: pointer;
            text-align: center;
            line-height: 50px;
            border-radius: 15px;
        }
        .second li{
            width: 80px;
            height: 50px;
            background-color: blue;
            border-radius: 50%;
            margin-top: 10px;
        }
        .second {
            display: none;
        }
        .first:hover .second{
            display: block;
            cursor: pointer;
        }
        .first:hover {
            background-color: pink;
        }
    </style>

<body>
    <div>
        <ul>
            <li>
                <p>一级标签</p>
                <ul>
                    <li>210.net.cn</li>
                    <li>210.mn</li>
                </ul>
            </li>

            <li>
                <p>一级标签</p>
                <ul>
                    <li>210.net.cn</li>
                    <li>210.mn</li>
                </ul>
            </li>
        </ul>
    </div>

</body>
</html>

评论