纯CSS实现选项卡

这款选项卡是没有任何JS的,而是通过锚点以及伪类来实现。

HTML:

    <div class="news-btn">
      <a href="#news1">news1</a>
      <a href="#news2">news2</a>
      <a href="#news3">news3</a>
    </div>
    <div class="news-show">
      <div id="news1">this is news1</div>
      <div id="news2">this is news2</div>
      <div id="news3">this is news3</div>
    </div>

CSS:

      * {
        margin: 0;
        padding: 0;
      }

      :root {
        padding: 100px 0 0 100px;
      }

      .news-btn {
        width: 300px;
        height: 40px;
        display: flex;
      }

      .news-btn > a {
        width: 100px;
        display: flex;
        justify-content: center;
        align-items: center;
        text-decoration: none;
        color: #fff;
      }

      a:first-of-type {
        background-color: yellowgreen;
      }

      a:nth-of-type(2) {
        background-color:violet;
      }

      a:last-of-type {
        background-color: tomato;
      }

      a:hover {
        opacity: 0.8;
      }

      .news-show {
        box-sizing: border-box;
        width: 300px;
        height: 300px;
        border: 2px solid red;
        overflow: hidden;
      }

      .news-show > div {
        width: 300px;
        height: 300px;
        text-align: center;
        line-height: 300px;
        font-size: 30px;
      }

      :target {
        color: red;
      }

实现效果如下(Chrome):
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值