WEB选项卡开发

代码实现效果如

2.png

代码演示

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

<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;
        }

        .mostoutsidebox {
            width: 75rem;
            height: 50rem;
            display: flex;
            flex-direction: column;
            margin: 0 auto;
            border: 2px solid #209de1;
            border-radius: 1rem;
            overflow: hidden;
        }

        .headerbox {
            width: 100%;
            height: 10rem;
            border-bottom: 2px solid #0ee2b8;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        .bt {
            width: 33.33%;
            height: 10rem;
            border: 1px solid #000;
            border-radius: 1rem;
            text-align: center;
            line-height: 10rem;
            font-size: 2rem;
            cursor: pointer;
        }

        .mostoutsidebox .bt:last-child {
            border-right: none;
        }

        .mostoutsidebox .bt:hover {
            background-color: #a55de0;
            color: #fff;
        }

        .bodybox {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
            background-color: #afec07;
        }

        .nr {
            width: 100%;
            height: 100%;
            position: absolute;
            color: #fff;
            font-size: 2rem;
            text-align: center;
            display: none;
        }

        .nr:nth-of-type(1) {
            display: block;
            background-color: #ea980a;
        }

        .nr:nth-of-type(2) {
            background-color: #df4808;
        }

        .nr:nth-of-type(3) {
            background-color: #f410ac;
        }
    </style>
</head>

<body>
    <div class="mostoutsidebox">
        <div class="headerbox">
            <div class="bt">标题1</div>
            <div class="bt">标题2</div>
            <div class="bt">标题3</div>
        </div>
        <div class="bodybox">
            <div class="nr">内容1</div>
            <div class="nr">内容2</div>
            <div class="nr">内容3</div>
        </div>
    </div>
    <script>
        let tts = document.getElementsByClassName('bt');
        for (let i = 0; i < tts.length; i++) {
            tts[i].onmouseenter = function () {
                console.log("鼠标移入第" + i + "个按钮");
                let tcs = document.getElementsByClassName('nr');
                for (let j = 0; j < tcs.length; j++) {
                    tcs[j].style.display = 'none';
                }
                tcs[i].style.display = 'block';
                for (let k = 0; k < tts.length; k++) {
                    tts[k].classList = 'bt';
                }
                tts[i].classList = ('bt active');
            }
        }

    </script>
</body>

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