web第五次作业

用html实现如下效果

image.png

代码如下

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

<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 {
            width: 100%;
            height: 100%;
        }

        html {
            font-size: 10px;
        }

        .mostoutbox {
            width: 100%;
            height: 5rem;
            background-color: #22ccfb;

            display: flex;
            justify-content: center;

        }

        .mostbox {
            width: 120rem;
            line-height: 5rem;
            display: flex;
        }

        .mostbox .morebox {
            padding: 0 5rem;
            height: 100%;
            line-height: 5rem;
            text-align: center;
            cursor: pointer;
            background-color:#c0acc8;
            font-size: 1.8rem;
            position: relative;
        }

        .mostbox .morebox:hover {
            background-color: #a1e740;
            color: #0a0808;
        }

        .mostbox .morebox .box {
            list-style: none;
            background-color: #dfa99f;
            position: absolute;
            top: 5rem;
            left: 0;
            display: none;
        }

        .box li {
            padding: 1rem 2rem;
        }

        .box li:hover {
            background-color: #a140e7;
            color: #0a0808;
        }
    </style>
</head>

<body>
    <div class="mostoutbox">
        <div class="mostbox">
            <div class="morebox">
                首页
            </div>
            <div class="morebox">
                相册<ul class="box">
                    <li>
                        我的相册
                    </li>
                    <li>
                        上传照片
                    </li>
                    <li>
                        查看相册
                    </li>
                </ul>
            </div>
            <div class="morebox">
                文章 <ul class="box">
                    <li>
                        我的文章
                    </li>
                    <li>
                        发布文章
                    </li>
                    <li>
                        查看文章
                    </li>
                </ul>
            </div>
            <div class="morebox">
                消息<ul class="box">
                    <li>
                        我的留言
                    </li>
                    <li>
                        我的私言
                    </li>
                    <li>
                        发送消息
                    </li>
                </ul>
            </div>

        </div>
    </div>

    <script>
        let _lis = document.getElementsByClassName('morebox');
        for (let i = 0; i < _lis.length; i++) {
            _lis[i].onmouseenter = function () {
                let box = _lis[i].getElementsByClassName('box');
                if (box.length > 0) {
                    box[0].style.display = 'block';
                }
            }

        }
    </script>
</body>

</html>


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

推荐阅读更多精彩内容