← 一覧へ

Tab Menu / 06 ダーク|Dark

デザイン見本

  • Tab 1
  • Tab 2
  • Tab 3
Good morning. This is the content of Tab 1.
Hello. This is the content of Tab 2.
Good evening. This is the content of Tab 3.

黒とダークグレーを基調とした、目に優しいダークモードデザインです。選択中のタブは背景色が変化し、インセットシャドウによって押されたような奥行きを表現しています。開発者向けドキュメントや、落ち着いた雰囲気のブログにマッチします。

実装コード

HTML
<div class="tab-container">
  <ul>
    <li class="selected" data-id="tab-1">Tab 1</li>
    <li data-id="tab-2">Tab 2</li>
    <li data-id="tab-3">Tab 3</li>
  </ul>
  <div class="tab-content selected" id="tab-1">
    Tab 1 のコンテンツ
  </div>
  <div class="tab-content" id="tab-2">
    Tab 2 のコンテンツ
  </div>
  <div class="tab-content" id="tab-3">
    Tab 3 のコンテンツ
  </div>
</div>
CSS
.tab-container ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  background: #1a1a1a;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}

.tab-container ul li {
  flex: 1;
  padding: 16px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #888;
  border-right: 1px solid #333;
}

.tab-container ul li:last-child {
  border-right: none;
}

.tab-container ul li.selected {
  color: #fff;
  background: #333;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.tab-container ul li:not(.selected):hover {
  background: #2a2a2a;
  color: #ccc;
}

.tab-container .tab-content {
  display: none;
  padding: 24px;
  min-height: 150px;
  background: #2a2a2a;
  color: #fff;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tab-container .tab-content.selected {
  display: block;
}
JS
const tabContainer = document.querySelector('.tab-container');
const tabMenuItems = tabContainer.querySelectorAll('ul li');
const tabContents = tabContainer.querySelectorAll('.tab-content');

tabMenuItems.forEach(tabMenuItem => {
  tabMenuItem.addEventListener('click', () => {
    tabMenuItems.forEach(item => {
      item.classList.remove('selected');
    });
    tabMenuItem.classList.add('selected');

    tabContents.forEach(tabContent => {
      tabContent.classList.remove('selected');
    });
    document.getElementById(tabMenuItem.dataset.id).classList.add('selected');
  });
});