下拉菜单

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>菜单</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html,
        body {
            height: 100%;
            width: 100%;
        }

        html {
            font-size: 10px;
        }

        .nav {
            width: 100%;
            height: 5rem;
            background-color: antiquewhite;
            display: flex;
            justify-content: center;
        }

        .content {
            width: 120rem;
            display: flex;
        }

        .content .items {
            font-size: 1rem;
            list-style: none;
            height: 100%;
            padding: 0 5rem;
            text-align: center;
            line-height: 5rem;
            cursor: pointer;
            position: relative;
        }

        .content .items:hover {
            background-color: #fff;
            color: #333;
        }

        .children {
            list-style: none;
            background-color: antiquewhite;
            position: absolute;
            left: 0;
            top: 5rem;
            display: none;
            width: 100%;
        }

        .items:hover .children {
            display: block;
        }

        .children li {
            padding: 1rem 2rem;
            position: relative;
            text-align: left;
        }

        .children li:hover {
            background-color: aquamarine;
            color: #333;
        }
    </style>
</head>

<body>
    <div class="nav">
        <ul class="content">
            <li class="items">首页</li>
            <li class="items">文章
                <ul class="children">
                    <li>发表文章</li>
                    <li>我的文章</li>
                    <li>文章管理</li>
                    <li>文章分类</li>
                </ul>
            </li>
            <li class="items">相册
                <ul class="children">


                    <li>我的相册</li>
                    <li>储存相册</li>
                    <li>相册管理</li>
                    <li>相册分类</li>
                </ul>
            </li>
            <li class="items">消息
                <ul class="children">
                    <li>我的消息</li>
                    <li>发送消息</li>
                    <li>删除消息</li>
                    <li>复制消息</li>
                </ul>
            </li>
            <li class="items">设置
                <ul class="children">
                    <li>个人设置</li>
                    <li>系统设置</li>
                    <li>安全设置</li>
                    <li>通知设置</li>
                </ul>
            </li>

        </ul>

    </div>

    <script>
        let _lis = document.grtElementsByClassName("items")
        for (let i = 0; i < _lis.length; i++) {
            _lis[i].onmouseenter = function () {
                let child = _lis[i].grtElementsByClassName("children")
                if (child.length > 0) {
                    child[0].style.display = "block"
                }
            }
            _lis[i].onmouseleave = function () {
                let child = _lis[i].grtElementsByClassName("children")
                if (child.length > 0) {
                    child[0].style.display = "none"
                }
            }
        }
    </script>
</body>

</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容