下拉菜單

作業(yè)分析

本次使用html與js樣式編寫效果如下


屏幕截圖 2025-03-27 192443.png

屏幕截圖 2025-03-27 192448.png

代碼實(shí)現(xiàn)

使用html代碼實(shí)現(xiàn)

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

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

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

        html {
            font-size: 10px;
        }

        .bg {
            display: flex;
            justify-content: center;
            height: 5rem;
            width: 100%;
        }

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

            line-height: 5rem;
            justify-content: space-evenly;
            list-style: none;
            font-size: 2rem;
            font-weight: 30;
        }

        .content .item {
            height: 100%;
            padding: 0 5rem;
            text-align: center;
            cursor: pointer;
            position: relative;
        }

        .content .item :hover {
            background-color: aqua;
            color: #000;
        }

        .chi {
            list-style: none;
            background-color: aqua;
            position: absolute;
            left: 0;
            top: 5rem;
            display: none;
        }

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

        .chi li :hover {
            background-color: aqua;
            color: #000;
        }
    </style>
</head>

<body>
    <div class="bg">
        <ul class="content">
            <li class="item">首頁</li>
            <li class="item">文章
                <ul class="chi">
                    <li>我的文章</li>
                    <li>發(fā)表文章</li>
                </ul>
            </li>
            <li class="item">相冊(cè)
                <ul class="chi">
                    <li>我的相冊(cè)</li>
                    <li>上傳照片</li>
                </ul>
            </li>
            <li class="item">消息
                <ul class="chi">
                    <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 child = lis[i].getElementsByClassName("chi")
                if (child.length > 0) {
                    child[0].style.display = "block"
                }
            }

            lis[i].onmouseleave = function () {
                let child = lis[i].getElementsByClassName("chi")
                if (child.length > 0) {
                    child[0].style.display = "none"
                }
            }
        }
    </script>
</body>

</html>
#個(gè)人總結(jié)
要熟練運(yùn)用使用js中函數(shù)的運(yùn)用,以及對(duì)定義的熟練掌握,同時(shí)對(duì)標(biāo)簽的仔細(xì)檢查
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容