<div class="tab inner layout">
  <div class="tab__layout">
    <!-- 1つ目のタブとコンテンツ -->
    <label class="tab__button">
      <input type="radio" name="tab-2" checked>
      <p>タブ1</p>
    </label>
    <div class="tab__content">
      <p>1つ目のコンテンツ部分になります。</p>
    </div>

    <!-- 2つ目のタブとコンテンツ -->
    <label class="tab__button">
      <input type="radio" name="tab-2">
      <p>タブ2</p>
    </label>
    <div class="tab__content">
      <p>2つ目のコンテンツ部分になります。</p>
    </div>

    <!-- 3つ目のタブとコンテンツ -->
    <label class="tab__button">
        <input type="radio" name="tab-2">
        <p>タブ3</p>
    </label>
    <div class="tab__content">
      <p>3つ目のコンテンツ部分になります。</p>
    </div>
  </div>
</div>
/* リセットCSS */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* インナーとレイアウト調整 */
.inner {
  max-width: calc(1000px + 50px * 2);
  width: 100%;
  margin-right: auto;
  margin-left: auto;
  padding-right: 50px;
  padding-left: 50px;

  @media screen and (max-width: 767px) {
    padding-right: 30px;
    padding-left: 30px;
  }

  @media screen and (max-width: 600px) {
    padding-right: 20px;
    padding-left: 20px;
  }
}

.layout {
  margin-top: 100px;
}

/* タブ切り替えで使用するCSS */
.tab__layout {
  display: flex;
  flex-wrap: wrap;
  column-gap: 10px;


  &::after {
    content: '';
    display: block;
    width: 100%;
    height: 3px;
    background: #5CC0EF;
    order: -1;
  }
}

.tab__button {
  cursor: pointer;
  padding: 16px 20px;
  border-radius: 5px 5px 0 0;
  background-color: #ccc;
  color: #fff;
  text-align: center;
  transition: all 0.3s;
  //これがないと横並びにならない
  order: -1;
  //これがないとボタンの幅が均等にならない
  flex: 1 1;

  &:hover {
    opacity: 0.7;
  }

  input[type="radio"] {
    display: none;
  }
}

// アクティブなボタン
.tab__button:has(:checked) {
  cursor: default;
  background-color: #5CC0EF;

  &:hover {
    opacity: 1;
  }
}

.tab__content {
  width: 100%;
  height: 0;
  overflow: hidden;
  opacity: 0;
}

.tab__button:has(:checked) + .tab__content {
  height: auto;
  overflow: auto;
  opacity: 1;
  transition: .5s opacity;
  padding: 20px;
  border-top: none;
}

View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.