2025-04-01

本次要求在编写一个简易的选项卡效果效果


image.png
<!DOCTYPE html>
<html lang="th">

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

        html {
            font-size: 10px;
        }

        .tab {
            width: 40rem;
            height: 30rem;
            border: solid 1px #000;
        }

        .tab-title {
            width: 100%;
            height: 5rem;
            background-color: antiquewhite;
            border-bottom: solid 2px orange;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .tt {
            flex: 1;
            height: 5rem;
            background-color: #fff;
            font-size: 1.8rem;
            text-align: center;
            line-height: 5rem;
        }

        .tt.active,
        .tt:hover {
            background-color: orange;
            color: white;
        }

        .tab-content {
            width: 100%;
            height: calc(100% - 5rem);
            background-color: aquamarine;
            position: relative;
        }

        .tc {
            width: 100%;
            height: 100%;
            font-size: 1.8rem;
            text-align: center;
            color: white;
            position: absolute;
            display: none;
        }

        .tc.active {
            display: block;
        }

        .tc:nth-of-type(1) {
            background-color: blue;
        }

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

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

<body>
    <div class="tab">
        <div class="tab-title">
            <div class="tt active">标题1</div>
            <div class="tt">标题2</div>
            <div class="tt">标题3</div>
        </div>
        <div class="tab-content">
            <div class="tc active">内容部分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 () {
                for (let j = 0; j < tts.length; j++) {
                    tts[j].classList = "tt"
                }
                tts[i].classList = "tt active"
                let tcs = document.getElementsByClassName("tc")
                for (let x = 0; x < tcs.length; x++) {
                    tcs[x].classList = "tc"
                }
                tcs[i].classList = "tc active"
            }
        }
    </script>
</body>

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

推荐阅读更多精彩内容

  • 因为大概这是我基神这个系列最后一次出演了,即便前年在电脑上看过也还是为了男神去影院贡献下,没想到把第一次看没有特别...
    大蔚蔚阅读 525评论 0 0
  • 又是刷视频 年糕妈妈 三胎男娃 事业有成 很大的博主了 有资本成分的(其他报道看到的) 说自己现在是大妈心态 在星...
    赖小脾阅读 35评论 0 0
  • 无效化妆的尽头是玄学!当代女性的美妆修行实录 家人们谁懂啊!每天在脸上涂涂抹抹两小时,出门风吹五分钟直接打回原形,...
    繁华三千不过云烟阅读 43评论 0 1
  • 好久没有来简书了,因为不敢看已经写下的文字。今天来,依旧故意不看。 在你离开的一年时间,想想自己每天只有忙碌、各种...
    春花溪流阅读 50评论 0 0
  • 夏天前,请逼自己瘦下来 1.不吃晚餐 晚餐只吃低脂果蔬,而且尽量在8点前吃好,时常让自己保持着饥饿感,毕竟晚上不需...
    妞妞敦敦阅读 28评论 0 0