Bind the label to the corresponding checkbox, then hide the checkbox, and use the pseudo-class selector (: Checked) and the neighboring sibling selector (~ or +) to trigger show or hide.

If you want the “accordion” effect, just set the type of each checkbox to Radio.

There is a drawback, however, that each checkbox requires a unique ID and label binding.


       
<html lang="zh">
 
<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>
    .parent {
      width: 280px;
    }
    .la {
      display: inline-block;
      width: 100%;
      background-color: #f2f2f2;
      cursor: pointer;
      height: 30px;
      line-height: 30px;
      border-bottom: 1px solid #ccc;
    }
 
    .t1 {
      display: none;
    }
 
    .content {
      height: 0px;
      overflow: hidden;
      transition: all .38s;
    }
 
    .t1:checked+.content {
      height: 100px;
    }
  </style>
</head>
 
<body>
  <div class="parent">
    <div>
      <label for="t1" class="la">check</label>
      <input type="checkbox" name="t" id="t1" class="t1">
      <div class="content">
        <p>Hello</p>
        <p>go go go</p>
      </div>
    </div>
    <div>
      <label for="t2" class="la">check</label>
      <input type="checkbox" name="t" id="t2" class="t1">
      <div class="content">
        <p>Hello</p>
        <p>go go go</p>
      </div>
    </div>
    <div>
      <label for="t3" class="la">check</label>
      <input type="checkbox" name="t" id="t3" class="t1">
      <div class="content">
        <p>Hello</p>
        <p>go go go</p>
      </div>
    </div>
  </div>
</body>
 
</html>
Copy the code