选项卡的设计

效果展示

屏幕截图 2025-03-28 200304.png

代码实现

<html lang="zh">

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

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

        body {
            font-size: 10px;
        }

        .tab {
            width: 450px;
            height: 300px;
            border: solid 2px #daae1e;
        }

        .tab-title {
            width: 100%;
            height: 30px;
            border-bottom: #daae1e 1px solid;
            display: flex;
            justify-content: space-between;
        }

        .tt {
            width: 33%;
            height: 100%;

            color: #aaeb11;
            text-align: center;
            line-height: 30px;
            cursor: pointer;
        }

        .tt:hover {
            background-color: #daae1e;
            color: #fff;
        }

        .tab-content {
            width: 100%;
            height: 270px;

            position: relative;

        }

        .tc {
            width: 100%;
            height: 270px;
            position: absolute;
            display: none;
            text-align: center;
        }

        .tc:nth-of-type(1) {
            background-color: bisque;
            display: block;
        }

        .tc:nth-of-type(2) {
            background-color: brown;
        }

        .tc:nth-of-type(3) {
            background-color: chartreuse;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab-title">
            <div class="tt">标题一</div>
            <div class="tt">标题二</div>
            <div class="tt">标题三</div>

        </div>
        <div class="tab-content">
            <div class="tc">内容一</div>
            <div class="tc">内容二</div>

            <div class="tc">内容三</div>
        </div>
    </div>

</body>
<script>
    let tts = document.getElementsByClassName("tt")
    for (let i = 0; i < tts.length; i++) {
        tts[i].onmouseenter = function () {
            console.log("鼠标进入了" + i + "个标题")
            let tcs = document.getElementsByClassName("tc")
            for (let j = 0; j < tcs.length; j++) {
                tcs[j].style.display = "none"
            }
            tcs[i].style.display = "block"
            for (let x = 0; x < tts.length; x++) {
                tts[x].className = "tt"
            }
            tts[i].classList = "tt active"
        }
    }
</script>

</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容