选项卡效果

作业分析

本次使用html与js样式编写效果如下


屏幕截图 2025-03-26 195840.png
屏幕截图 2025-03-26 195846.png

屏幕截图 2025-03-26 195851.png

代码实现

使用html代码实现

<!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>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

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

        html {
            font-size: 10px;
        }

        .tab {
            width: 30rem;
            height: 40rem;
            border: solid 2px burlywood;
            border-radius: 6px;
            overflow: hidden;
        }

        .tab-title {
            width: 100%;
            height: 5rem;
            display: flex;
            justify-content: space-between;
            border-bottom: solid 2px burlywood;
            border-right: 2px;
        }

        .tt {
            width: 33%;
            height: 100%;
            font-size: 7px;
            text-align: center;
            border-right: solid 2px burlywood;
            line-height: 4rem;
        }

        .tt:nth-of-type(1) {
            color: white;
            background-color: burlywood;
        }

        .tt:nth-last-child(1) {
            border-right: none;
        }

        .tt:hover {
            color: white;
            background-color: burlywood;
        }

        .tab-content {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
        }

        .tc {
            position: absolute;
            text-align: center;
            width: 100%;
            height: 100%;
            font-size: 7px;
        }

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

        .tc:nth-of-type(2) {
            background-color: #cead05;
            display: none;
        }

        .tc:nth-of-type(3) {
            background-color: #1024d6;
            display: none;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab-title">
            <div class="tt">标题1</div>
            <div class="tt">标题2</div>
            <div class="tt">标题3</div>
        </div>
        <div class="tab-content">
            <div class="tc">内容1</div>
            <div class="tc">内容2</div>
            <div class="tc">内容3</div>
        </div>
    </div>
    <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"
            }
        }
    </script>
</body>

</html>
#个人总结

对于本次js标签使用,需要熟练掌握<get> <for>....等标签内容,同时还有参数的定义,以及对函数的熟练掌握
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容