Page Widget How to - Create accordion panel








Question

We would like to know how to create accordion panel.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
<!-- w ww .j a v a2s .  c  o m-->
.ac-container label {
  position: relative;
  z-index: 20;
  display: block;
  height: 30px;
  cursor: pointer;
  color: #777;
  background: #EEE;
}

.ac-container label:hover {
  background: #fff;
}

.ac-container input {
  display: none;
}

.ac-container section {
  background: rgba(255, 255, 255, 0.5);
  margin-top: -1px;
  overflow: hidden;
  max-height: 0px;
  position: relative;
  z-index: 10;
  -webkit-transition: max-height 0.3s ease-in-out, box-shadow 0.6s linear;
  -moz-transition: max-height 0.3s ease-in-out, box-shadow 0.6s linear;
  -o-transition: max-height 0.3s ease-in-out, box-shadow 0.6s linear;
  -ms-transition: max-height 0.3s ease-in-out, box-shadow 0.6s linear;
  transition: max-height 0.3s ease-in-out, box-shadow 0.6s linear;
}

.ac-container section p {
  font-style: italic;
  color: #777;
  line-height: 23px;
  font-size: 14px;
  padding: 20px;
  text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.8);
}

.ac-container input:checked ~ section {
  -webkit-transition: max-height 0.5s ease-in-out, box-shadow 0.1s linear;
  -moz-transition: max-height 0.5s ease-in-out, box-shadow 0.1s linear;
  -o-transition: max-height 0.5s ease-in-out, box-shadow 0.1s linear;
  -ms-transition: max-height 0.5s ease-in-out, box-shadow 0.1s linear;
  transition: max-height 0.5s ease-in-out, box-shadow 0.1s linear;
  box-shadow: 0px 0px 0px 1px rgba(155, 155, 155, 0.3);
}

.ac-container input:checked ~ section.ac-small {
  max-height: 500px; /*auto*/
}
</style>
</head>
<body>
  <div class="ac-container">
    <div>
      <input id="ac-1" name="accordion-1" type="checkbox" />
      <section class="ac-small">
        <p>test <br/>test <br/>test <br/>test <br/>test <br/>
        test <br/>test <br/>test <br/>test <br/>test <br/>
        test <br/>test <br/>test <br/>test <br/>test <br/>
        test <br/>test <br/>test <br/>test <br/>test <br/>
        test <br/>test <br/>test <br/>test <br/>test <br/>
        </p>
      </section>
      <label for="ac-1">About us</label>
    </div>
    <div>
      <input id="ac-2" name="accordion-2" type="checkbox" />
      <section class="ac-small">
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
        <p>Some content...</p>
      </section>
      <label for="ac-2">About us</label>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: