web选项卡开发

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
</head>
<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:5 rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #ccc;
        color:#fff;
    }
    .tt{
        flex:1;
        height: 5rem;
        background-color: rgba(123, 232, 176, 0.7);
        text-align: center;
        line-height: 5rem;
        font-size: 1.8rem;
    }
    .tt.active,
    .tt:hover{
        background-color: rgb(243, 223, 188);
        color: blueviolet;
    }
    .table-content{
        width: 100%;
        height: 25rem;
        background-color: #e87676;
        position: relative;
    }
    .tc{
        width: 100%;
        height: 25rem;
        text-align: center;
        background-color: #c03535;
        font-size: 1.8rem;
        display: none;
        position: absolute;
    }
   .tc.active{
        display: block;
    }
    .tc:nth-of-type(1){
        background-color: rgb(34, 107, 253);
    }
    .tc:nth-of-type(2){
        background-color: darkorange;
    }
    .tc:nth-of-type(3){
        background-color: darkslateblue;
    }


</style>
<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="table-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")
        console.log(tts)
        for(let i=0;i<tts.length;i++){
            console.log(tts[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 k=0;k<tcs.length;k++){
                    tcs[k].classList="tc"
                }
                tcs[i].classList="tc active"
            }
        }
        
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值