Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <div class='tab'>
    <div class='tab__buttons'>
      <button class="tab__button js-tab-button">タブ1</button>
      <button class="tab__button js-tab-button">タブ2</button>
      <button class="tab__button js-tab-button">タブ3</button>
    </div>
    <div class='tab__contents'>
      <div class="tab__item is-active js-tab-item">
        <img src="https://images.unsplash.com/photo-1712213197490-3de6360eaafb?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MTQ0MzA5ODR8&ixlib=rb-4.0.3&q=85" />
      </div>
      <div class="tab__item js-tab-item"><img src="https://images.unsplash.com/photo-1713279507772-07aa1942a343?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MTQ0MzA5ODR8&ixlib=rb-4.0.3&q=85" /></div>
      <div class="tab__item js-tab-item"><img src="https://images.unsplash.com/photo-1713962488123-80b6b07a7c64?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MTQ0MzA5ODR8&ixlib=rb-4.0.3&q=85" /></div>
    </div>
  </div>
  </div>
</body>
              
            
!

CSS

              
                body {
  width: 300px;
  margin: 0 auto;
}

.tab {
  margin-top: 50px;
  width: 100%;
}

.tab__buttons {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.tab__button {
  width: 33%;
  cursor: pointer;
}

.tab__contents {
  margin-top: 20px;
}

.tab__item {
  display: none;
}

.tab__item.is-active {
  display: block;
}

.tab__item img {
  aspect-ratio: 100 / 100;
  width: 100%;
}

              
            
!

JS

              
                $(function () {
  // 該当するクラスを変数に格納する。→コード量の節約
  const tabButton = $(".js-tab-button"),
    tabItem = $(".js-tab-item");
  // tabButtonをクリックすると処理が発火する。
  tabButton.on("click", function () {
    // 並列で並んでる内の、何番目のtabButtonかを取得
    let index = tabButton.index(this);
    // tabButtonとtabItemに初期状態でついている、"is-active"を削除
    tabButton.removeClass("is-active");
    tabItem.removeClass("is-active");
    // 該当するindexのtabButtonとtabItemに"is-active"を付与
    tabButton.eq(index).addClass("is-active");
    tabItem.eq(index).addClass("is-active");
  });
});

              
            
!
999px

Console