css:常见问答手风琴效果

要点:
1、利用label标签来绑定复选框获取焦点,不用点点小框框
2、内容的显示和隐藏:得用overflow属性和max-height
3、兄弟选择器的使用:+ ~

贴上代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      body {
        display: flex;
        min-height: 100vh;
        align-items: center;
        justify-content: center;
        background: #f5f8ff;
      }
      .container {
        max-width: 600px;
        display: flex;
      }
      .container .tab{
        background: greenyellow;
        box-shadow: 0 15px 25px rgba(0, 0, 0, 0.05);
        padding: 0 20px 20px;
        position: relative;
      }
      .container .tab input{
        appearance: none;
        /* display: none; */
      }
      .container .tab label{
        display: flex;
        align-items: center;
      }
      .container .tab label::after{
        content: '+';
        position: absolute;
        right:20px;
        font-size: 2em;
        color: #eee;
        transition: transform 0.5s;
      }
      .container .tab input:checked~label::after{
        content:'+';
        color: #000;
        transform: rotate(135deg);
      }
      .container .tab label h2{
        width:40px;
        height: 40px;
        line-height: 40px;
        color: #fff;
        text-align: center;
        background: #333;
        border-radius: 5px;
      }

      .container .tab .content{
        max-height: 0;
        overflow: hidden;
        transition: all 1s;
      }

      .container .tab input:checked~.content{
        max-height: 100vh;
      }

    </style>
  </head>
  <body>
    <div class="container">
      <div class="tab">
        <input type="checkbox" id="acc1" />
        <label class="title" for="acc1">
          <h2>01</h2>
          <h3>手风琴效果练习</h3>
        </label>
        <div class="content">
          <p>
            阿斯蒂芬苦啊右啊夼基进丫苦工时期哩基本上弎堪塔顶载打发打发弎苦苦莾
            塔城地基蓐 蓐 苦工
          </p>
        </div>
      </div>
    </div>
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值