Tab Menu / 23 シンプルボーダー|Simple Border
デザイン見本
- 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;
border-bottom: none;
}
.tab-container ul li {
flex: 1;
padding: 16px 24px;
text-align: center;
cursor: pointer;
position: relative;
color: #999;
font-weight: 300;
letter-spacing: 0.5px;
border: none;
border-bottom: 2px solid #333;
border-radius: 8px 8px 0 0;
margin: 0;
}
.tab-container ul li.selected {
color: #333;
font-weight: 500;
background-color: #f0f0f0;
border: 2px solid #333;
border-bottom: none;
}
.tab-container .tab-content {
display: none;
padding: 32px 24px;
min-height: 150px;
color: #666;
line-height: 1.6;
border: 2px solid #333;
border-top: none;
border-radius: 0 0 8px 8px;
background: #f0f0f0;
margin-top: -2px;
}
.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');
});
});