Parts

Parts

開閉を利用したパーツ 2

項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。

コードの詳細はこちら
項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。

コードの詳細はこちら
項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。項目タイトルの閉じられている内容です。

コードの詳細はこちら

「accordion__content」というクラス名の中に隠す内容を入れる。
「label」のfor名と「input」のid名は項目ごとにかぶらない名前を付ける。


<div class="accordionBox--type02">
  <!--項目ここから-->
  <div class="accordion">
    <input type="checkbox" id="accordion--type02__label001" />
    <label for="accordion--type02__label001">項目タイトル 01</label>
    <div class="accordion__content">
      <!--隠す中身ここから-->
      項目タイトルをクリックすると現れる内容はここに書く。
      <!--隠す中身ここまで-->
      <!--//.accordion__content-->
    </div>
    <!--//.accordion-->
  </div>
  <!--//項目ここまで-->

  <!--項目ここから-->
  <div class="accordion">
    <input type="checkbox" id="accordion--type02__label002" />
    <label for="accordion--type02__label002">項目タイトル 02</label>
    <div class="accordion__content">
      <!--隠す中身ここから-->
      項目タイトルをクリックすると現れる内容はここに書く。
      <!--隠す中身ここまで-->
      <!--//.accordion__content-->
    </div>
    <!--//.accordion-->
  </div>
  <!--//項目ここまで-->

  <!--項目ここから-->
  <div class="accordion">
    <input type="checkbox" id="accordion--type02__label003" />
    <label for="accordion--type02__label003">項目タイトル 03</label>
    <div class="accordion__content">
      <!--隠す中身ここから-->
      項目タイトルをクリックすると現れる内容はここに書く。
      <!--隠す中身ここまで-->
      <!--//.accordion__content-->
    </div>
    <!--//.accordion-->
  </div>
  <!--//項目ここまで-->
  <!--//.accordionBox-->
</div>
                

.accordionBox--type02 {
  overflow: hidden;
  .accordion {
    > label {
      display: block;
      padding: 0.9em 1em 0.9em 3em;
      color: #fff;
      background: #666;
      cursor: pointer;
      transition: 0.3s all ease;
      position: relative;
      &::after {
        content: "";
        width: 0.8em;
        height: 0.8em;
        display: block;
        background: url("/img/icon/plus-circle.svg") no-repeat center center;
        background-size: 100% auto;
        filter: brightness(0) saturate(100%) invert(100%) sepia(0%) saturate(0%);
        position: absolute;
        top: 50%;
        left: 1.4em;
        margin-top: -0.4em;
        transition: all 0.5s;
      }
      &:hover {
        background: #888;
      }
    }
    &:nth-child(even) label {
      background: #444;
      &:hover {
        background: #888;
      }
    }
    > input[type="checkbox"] {
      display: none;
      + label + .accordion__content {
        height: 0;
        padding: 0;
        overflow: hidden;
        opacity: 0;
        transition: 0.5s;
      }
      &:checked {
        + label {
          background: #ddd;
          color: #000;
          &:hover {
            background: #ccc;
          }
          &::after {
            background: url("/img/icon/minus-circle.svg") no-repeat center center;
            background-size: 100% auto;
          }
          + .accordion__content {
            height: auto;
            padding: 0.5em 1em;
            opacity: 1;
          }
        }
      }
    }
  }
}
              
ページ上部に戻るスプーン