- 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="container">
<h1>Design 18: メタリック風</h1>
<div class="tab-container tab-design">
<ul>
<li class="selected" data-id="tab-18-1">Tab 1</li>
<li data-id="tab-18-2">Tab 2</li>
<li data-id="tab-18-3">Tab 3</li>
</ul>
<div class="tab-content selected" id="tab-18-1">
Good morning. This is the content of Tab 1.
</div>
<div class="tab-content" id="tab-18-2">
Hello. This is the content of Tab 2.
</div>
<div class="tab-content" id="tab-18-3">
Good evening. This is the content of Tab 3.
</div>
</div>
</div>
CSS
.container {
max-width: 800px;
width: 100%;
}
h1 {
text-align: center;
color: #fff;
margin-bottom: 40px;
font-size: 2.5em;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
/* ===== デザイン: メタリック風 ===== */
.tab-design {
overflow: hidden;
border-radius: 12px;
position: relative;
background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
border: 2px solid #95a5a6;
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.4),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.tab-design::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
repeating-linear-gradient(
45deg,
transparent,
transparent 10px,
rgba(255, 255, 255, 0.03) 10px,
rgba(255, 255, 255, 0.03) 20px
);
pointer-events: none;
}
.tab-design ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
border-radius: 12px 12px 0 0;
overflow: hidden;
position: relative;
border-bottom: 2px solid #95a5a6;
}
.tab-design ul::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 1px;
background: linear-gradient(90deg,
transparent 0%,
#ecf0f1 50%,
transparent 100%);
animation: metallicShine 3s ease-in-out infinite;
}
@keyframes metallicShine {
0%, 100% { opacity: 0.3; }
50% { opacity: 1; }
}
.tab-design ul li {
flex: 1;
padding: 18px 24px;
text-align: center;
cursor: pointer;
transition: all 0.4s ease;
position: relative;
color: #bdc3c7;
font-weight: 600;
font-family: 'Arial', sans-serif;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 1px;
border-right: 1px solid #7f8c8d;
background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
overflow: hidden;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.tab-design ul li:last-child {
border-right: none;
}
.tab-design ul li::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(135deg,
rgba(255, 255, 255, 0.1) 0%,
rgba(255, 255, 255, 0.05) 50%,
rgba(255, 255, 255, 0.1) 100%);
opacity: 0;
transition: opacity 0.4s ease;
}
.tab-design ul li:hover::before {
opacity: 1;
}
.tab-design ul li.selected {
color: #ecf0f1;
background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
box-shadow:
0 4px 16px rgba(231, 76, 60, 0.5),
inset 0 2px 4px rgba(255, 255, 255, 0.2),
inset 0 -2px 4px rgba(0, 0, 0, 0.3);
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
font-weight: 700;
animation: metallicPulse 2s ease-in-out infinite alternate;
}
@keyframes metallicPulse {
from {
box-shadow:
0 4px 16px rgba(231, 76, 60, 0.5),
inset 0 2px 4px rgba(255, 255, 255, 0.2),
inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}
to {
box-shadow:
0 6px 20px rgba(231, 76, 60, 0.7),
inset 0 2px 4px rgba(255, 255, 255, 0.3),
inset 0 -2px 4px rgba(0, 0, 0, 0.4);
}
}
.tab-design ul li.selected::after {
content: '';
position: absolute;
bottom: -2px;
left: 0;
right: 0;
height: 2px;
background: linear-gradient(90deg, #e74c3c, #c0392b);
box-shadow: 0 0 10px rgba(231, 76, 60, 0.8);
}
.tab-design ul li:not(.selected):hover {
background: linear-gradient(135deg, #3d4852 0%, #2c3e50 100%);
color: #ecf0f1;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
transform: translateY(-1px);
box-shadow:
0 2px 8px rgba(0, 0, 0, 0.3),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.tab-design .tab-content {
display: none;
padding: 30px;
min-height: 180px;
background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
color: #ecf0f1;
border-radius: 0 0 12px 12px;
box-shadow:
0 4px 16px rgba(0, 0, 0, 0.4),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
border: 1px solid #95a5a6;
border-top: none;
position: relative;
overflow: hidden;
}
.tab-design .tab-content::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
repeating-linear-gradient(
90deg,
transparent,
transparent 30px,
rgba(255, 255, 255, 0.02) 30px,
rgba(255, 255, 255, 0.02) 32px
);
pointer-events: none;
}
.tab-design .tab-content.selected {
display: block;
animation: metallicFadeIn 0.5s ease;
}
@keyframes metallicFadeIn {
from {
opacity: 0;
transform: translateY(-15px);
box-shadow:
0 2px 8px rgba(0, 0, 0, 0.4),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
to {
opacity: 1;
transform: translateY(0);
box-shadow:
0 4px 16px rgba(0, 0, 0, 0.4),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
}
JavaScript
// タブコンテナを取得
const tabContainer = document.querySelector('.tab-design');
const tabMenuItems = tabContainer.querySelectorAll('ul li');
const tabContents = tabContainer.querySelectorAll('.tab-content');
tabMenuItems.forEach(tabMenuItem => {
tabMenuItem.addEventListener('click', () => {
// 全てのタブからselectedクラスを外す
tabMenuItems.forEach(item => {
item.classList.remove('selected');
});
// クリックされたタブのみselectedクラスを付ける
tabMenuItem.classList.add('selected');
// 全てのタブのコンテンツからselectedクラスを外す
tabContents.forEach(tabContent => {
tabContent.classList.remove('selected');
});
// クリックされたタブのカスタムデータ属性と同じIDを持つコンテンツに、selectedクラスを付ける
document.getElementById(tabMenuItem.dataset.id).classList.add('selected');
});
});