2025-03-28 选项卡开发

<!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;
        }
        body,
        html{
            height: 100%;
            width: 100%;
        }
        html{
            font-size: 10px;
        }
        .tab{
            height: 30rem;
            width: 40rem;
            background-color: antiquewhite;
            display: flex;
            justify-content: center;
            flex-direction: column;
            border: solid 2px orange;
            border-radius: 8px;
            overflow: hidden;
        }
        .title{
            width: 100%;
            height: 5rem;
            background-color: aqua;
            border-bottom: solid 1px orange;
            display: flex;
            flex-direction: row;
        }
        .title .tt{
            flex: 1;
            height: 5rem;
            line-height: 5rem;
            text-align: center;
            font-size: 1.6rem;
            cursor: pointer;
            border-right: solid 1px orange;
        }
        .tt:hover{
            background-color: orange;
            color: white;
        }
        .tt:nth-of-type(1){
            background-color: orange;
            color: white;
        }
        .tab-content{
            width: 100%;
            height: 100%;
            background-color: aquamarine;
            position: relative;
            /* overflow: hidden; */

        }
        .tc{
            text-align: center;
            font-size: 1.4rem;
            position: absolute;
            display: none;
            
        }
        .tc:nth-of-type(1){
            display: block;
            width: 100%;
            height: 100%;
            background-color: azure;
        }
        .tc:nth-of-type(2){
            width: 100%;
            height: 100%;
            background-color: beige;
        }
        .tc:nth-of-type(3){
            width: 100%;
            height: 100%;
            background-color: burlywood;
        }
    </style>
</head>
<body>
    <div class="tab">
        <div class="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"
                for(let x;x<tts.length;x++){
                    tts[x].classList="tt"
                }

                tts[i].classList="tt active"
                
            }
        }


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

相关阅读更多精彩内容

友情链接更多精彩内容