2021-08-13 css-js-炫酷的原生选项卡切换

先看看效果

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .tab-navbar {
      display: flex;
      overflow: hidden;
      flex-direction: column-reverse;
      border-radius: 10px;
      width: 300px;
      height: 400px;
    }
    .tab-navbar input {
      display: none;
    }
    .tab-navbar input:nth-child(1):checked ~ main ul {
      background-color: #f66;
      -webkit-transform: translate3d(0, 0, 0);
              transform: translate3d(0, 0, 0);
    }
    .tab-navbar input:nth-child(2):checked ~ main ul {
      background-color: #66f;
      -webkit-transform: translate3d(-25%, 0, 0);
              transform: translate3d(-25%, 0, 0);
    }
    .tab-navbar input:nth-child(3):checked ~ main ul {
      background-color: #f90;
      -webkit-transform: translate3d(-50%, 0, 0);
              transform: translate3d(-50%, 0, 0);
    }
    .tab-navbar input:nth-child(4):checked ~ main ul {
      background-color: #09f;
      -webkit-transform: translate3d(-75%, 0, 0);
              transform: translate3d(-75%, 0, 0);
    }
    .tab-navbar nav {
      display: flex;
      height: 40px;
      background-color: #f0f0f0;
      line-height: 40px;
      text-align: center;
    }
    .tab-navbar nav label {
      flex: 1;
      cursor: pointer;
      transition: all 300ms;
    }
    .tab-navbar main {
      flex: 1;
    }
    .tab-navbar main ul {
      display: flex;
      flex-wrap: nowrap;
      width: 400%;
      height: 100%;
      transition: all 300ms;
    }
    .tab-navbar main li {
      display: flex;
      justify-content: center;
      align-items: center;
      flex: 1;
      font-weight: bold;
      font-size: 20px;
      color: #fff;
    }

    .active, .tab-navbar input:nth-child(1):checked ~ nav label:nth-child(1), .tab-navbar input:nth-child(2):checked ~ nav label:nth-child(2), .tab-navbar input:nth-child(3):checked ~ nav label:nth-child(3), .tab-navbar input:nth-child(4):checked ~ nav label:nth-child(4) {
      background-color: #3c9;
      color: #fff;
    }

  </style>
</head>
<body>
  <p>
    要点:可切换内容的导航栏<br>
    场景:页面切换
  </p>
  <div class="bruce flex-ct-x">
    <div class="tab-navbar">
      <input type="radio" name="tab" id="tab1" checked>
      <input type="radio" name="tab" id="tab2">
      <input type="radio" name="tab" id="tab3">
      <input type="radio" name="tab" id="tab4">
      <nav>
        <label for="tab1">标题1</label>
        <label for="tab2">标题2</label>
        <label for="tab3">标题3</label>
        <label for="tab4">标题4</label>
      </nav>
      <main>
        <ul>
          <li>内容1</li>
          <li>内容2</li>
          <li>内容3</li>
          <li>内容4</li>
        </ul>
      </main>
    </div>
  </div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值