← 一覧へ

Tab Menu / 14 縦棒区切り|Vertical Divider

デザイン見本

  • 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 {
  overflow: hidden;
  position: relative;
  background: #fff;
}

.tab-container ul {
  margin: 0 24px;
  padding: 16px 24px;
  list-style: none;
  display: flex;
  background: transparent;
  position: relative;
  border: 1px solid #e0e0e0;
}

.tab-container ul li {
  flex: 1;
  padding: 8px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  color: #666;
  font-weight: 500;
  font-family: 'Arial', sans-serif;
  background: transparent;
  border-right: 1px solid #e0e0e0;
}

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

.tab-container ul li.selected {
  color: #333;
  font-weight: 600;
}

.tab-container ul li:not(.selected):hover {
  background: #eeeeee;
  color: #333;
}

.tab-container .tab-content {
  display: none;
  padding: 24px;
  min-height: 150px;
  background: #fff;
  color: #333;
  position: relative;
}

.tab-container .tab-content.selected {
  display: block;
  animation: simpleFadeIn 0.3s ease;
}

@keyframes simpleFadeIn {
  from {opacity: 0; transform: translateY(10px);}
  to {opacity: 1; transform: translateY(0);}
}
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');
  });
});