html页面实现tab切换

代码示例如下:

<div class="con">
    <ul class="tabWraps">
        <li class="tabActive">内容一</li>
        <li>内容二</li>
    </ul>
    <div class="tabCon">
        <div class="detailCon">
            <div class="norLabel" style="cursor:pointer">点我切换</div>
            <div>我是内容一</div>
        </div>
        <div class="detailCon" style="display:none">
            我是内容二
        </div>
        <div class="detailCom" style="display:none">
            我是内容三
        </div>
    </div>
</div>

css:

.con{
    width: 350px;
    border:1px solid rgba(67, 172, 230, 1);
    background: rgba(73, 180, 253, 0.32);
    padding:10px;
    box-sizing: border-box;
}
.tabCon{
    font-size: 14px;
    color:#fff;
    font-weight: bold;
    margin-top: 15px;
}
.norLabel{
    text-align:center;
    color:#FE9393;
}
.tabWraps{
    font-size: 0;
    border:1px solid rgba(67, 172, 230, 1);
    background: rgba(73, 180, 253, 0.32);
    position:relative;  
    width: 294px;
    padding: 4px 14px; 
}
.tabWraps::before{
    content:'';
    position:absolute;
    width:2px;
    height: 19px;
    background:rgba(69, 255, 248, 1);
    top:6px;
    left: 50%;
}
.tabWraps li{
 width: 43%;
 height: 22px;
 line-height: 22px;
 text-align:center;
 font-size: 14px;
 font-family: SourceHanSansCN-Regular,
 SourceHanSansCN;
 font-weight: 400;
 color: #FFFFFF;
 display:inline-block;
 border-radius: 4px;
}
.tabWraps .tabActive{
 background:rgba(69, 205, 255, 1);
 border:1px solid rgba(69, 255, 248, 1);
}
.tabWraps li:nth-child(2){
    margin-left: 36px;
}

js:

<script src="dist/js/lib/jquery/jquery-3.3.1.min.js"></script>
    <script>
        $(function () {
                $('.tab-con .detailCon').first().show().siblings().hide()
                $('.tabWraps>li').click(function () {
                    $(this).addClass('tabActive').siblings().removeClass('tabActive')
                    var index = $(this).index()
                    $('.tabCon .detailCon').eq(index).show().siblings().hide()
                });
        // 点我切换点击事件
            $('.norLabel').click(function () {
                $('.tabCon .detailCon').hide()
                $('.tabCon .detailCom').show()
            });
        })

效果如下:
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值