2025-03-31

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

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

    html {
        font-size: 10px;
    }
    .bg{
        width: 100%;
        height: 5rem;
        background-color: antiquewhite;
        display: flex;
        justify-content: center;
    }
    .nav{
        width: 100rem;
        height: 5rem;
        display: flex;
        justify-content: start;
        gap: 20px;
        list-style: none;
    }
    .nav > .item{
        width: 20rem;
        height: 5rem;
        padding: 1rem 5rem;
        position: relative;
        text-align: center;
        cursor: pointer;
        font-size: 18px;

    }
    .nav > .item:hover{
        background-color: #f2f2;
        color: #333;
        font-weight: 500;
    }
    .children{
        list-style: none;
        position: absolute;
        background-color: brown;
        display: none;
        left: 0;
        top: 5rem;
        padding: 1rem 2rem;
        background-color: aquamarine;
    }
    .children > li{
        line-height: 5rem;
    }
    .children > li:hover{
        background-color: #f2f2f1;
        color: #333;
    }

    </style>

</head>
<body>
    <div class="bg">
        <ul class="nav">
            <li class="item">主页
            </li>
            <li class="item">文章
                <ul class="children">
                    <li>我的文章</li>
                    <li>文章编写</li>
                    <li>发表文章</li>
                </ul>
            </li>
            <li class="item">相册
                <ul class="children">
                    <li>全部相册</li>
                    <li>私密相册</li>
                    <li>共享相册</li>
                </ul>
            </li>
            <li class="item">留言
                <ul class="children">
                    <li>我的留言</li>
                    <li>别人的留言</li>
                    <li>去留言</li>
                </ul>
            </li>
        </ul>
    </div>
    <script>
        let _lis = document.getElementsByClassName("item")
        for (let i = 0; i < _lis.length; i++) {
            _lis[i].onmouseenter = function () {
                let _children = _lis[i].getElementsByClassName("children")
                if (_children.length > 0) {
                    let c = _children[0]
                    c.style.display = "block"
                }
            }
            _lis[i].onmouseleave = function () {
                let _children = _lis[i].getElementsByClassName("children")
                if (_children.length > 0) {
                    let c = _children[0]
                    c.style.display = "none"
                }
            }
        }
    </script>
</body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 岁月带走了纯真,时光苍老了容颜。人生短暂,有得有失,生活艰辛,有苦有乐。快乐是心的愉悦,幸福是心的满足。 一个人快...
    时光吖阅读 41评论 0 2
  • 岁月带走了纯真,时光苍老了容颜。人生短暂,有得有失,生活艰辛,有苦有乐。快乐是心的愉悦,幸福是心的满足。 一个人快...
    嗨嗨嗨_阅读 503评论 0 4
  • 下桃花雨和雪 桃花,木蘭花,迎春花都開了,但是總感覺它們開的有些局促,有些過於轟轟烈烈…… 桃花...
    野鸡和猫和老鷹阅读 23评论 0 0
  • (原创)他的拣选让人不得不谦卑 在至高者的各种作为中,最让人不得不谦卑的就是他对人的拣选和恩召。完全不是按照人所能...
    与真理约会阅读 36评论 0 0
  • 春日中医养生指南 春季阳气生发,万物复苏,是中医养生的关键时期。依据中医理论,顺应天时,能有效调养身心,为全年健康...
    2762103664阅读 27评论 0 0