美文网首页
纯css实现tab切换

纯css实现tab切换

作者: Allan要做活神仙 | 来源:发表于2019-03-04 17:44 被阅读0次

1、利用a标签target,点击之后对应id的div会有 :target 伪类。

<style type="text/css">
        *{
            margin: 0;
            padding: 0;
            text-decoration: none;
        }
        .tab{
            width: 300px;
            height: 300px;
            margin: 30px auto;
            overflow: hidden;
        }
        .nav{
            height: 30px
        }
        .content{
            height: 270px;
            overflow: hidden;
        }
        .cont{
            height: 270px;
        }
        #the1{
            background: green;
        }
        #the2{
            background: blue;
        }
    </style>
<div class="tab">
    <div class="nav">
        <a href="#the1">ONE</a>
        <a href="#the2">TWO</a>
    </div>
    <div class="content">
        <div id="the1" class="cont">第一张</div>
        <div id="the2" class="cont">第二张</div>
    </div>
</div>

2、利用radio按钮和:checked选择器

相关文章

网友评论

      本文标题:纯css实现tab切换

      本文链接:https://www.haomeiwen.com/subject/uvoiuqtx.html