- 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>Tab Design 9 - Glassmorphism</h1>
<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">
Good morning. This is the content of Tab 1.
</div>
<div class="tab-content" id="tab-2">
Hello. This is the content of Tab 2.
</div>
<div class="tab-content" id="tab-3">
Good evening. This is the content of Tab 3.
</div>
</div>
</div>
CSS
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
height: 100vh;
}
.container {
max-width: 800px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border-radius: 16px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
h1 {
text-align: center;
padding: 30px 20px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
color: white;
margin: 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
/* ===== Design 9: Glassmorphism ===== */
.tab-container {
overflow: hidden;
border-radius: 16px;
position: relative;
}
.tab-container::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
border-radius: 18px;
z-index: -1;
animation: gradientShift 6s ease infinite;
}
@keyframes gradientShift {
0%, 100% {
background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
}
25% {
background: linear-gradient(45deg, #4ecdc4, #45b7d1, #96ceb4, #feca57, #ff6b6b);
}
50% {
background: linear-gradient(45deg, #45b7d1, #96ceb4, #feca57, #ff6b6b, #4ecdc4);
}
75% {
background: linear-gradient(45deg, #96ceb4, #feca57, #ff6b6b, #4ecdc4, #45b7d1);
}
}
.tab-container ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border-radius: 16px 16px 0 0;
overflow: hidden;
position: relative;
border: 1px solid rgba(255, 255, 255, 0.2);
border-bottom: none;
}
.tab-container ul::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%);
pointer-events: none;
}
.tab-container ul li {
flex: 1;
padding: 18px 24px;
text-align: center;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
color: rgba(255, 255, 255, 0.8);
font-weight: 500;
letter-spacing: 0.5px;
border-right: 1px solid rgba(255, 255, 255, 0.1);
overflow: hidden;
}
.tab-container ul li:last-child {
border-right: none;
}
.tab-container ul li::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg,
transparent 0%,
rgba(255, 255, 255, 0.1) 50%,
transparent 100%);
transition: left 0.6s ease;
}
.tab-container ul li:hover::before {
left: 100%;
}
.tab-container ul li.selected {
color: #fff;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(30px);
-webkit-backdrop-filter: blur(30px);
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.3);
font-weight: 600;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.tab-container ul li.selected::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
animation: rainbowFlow 3s linear infinite;
}
@keyframes rainbowFlow {
0% { background-position: 0% 50%; }
100% { background-position: 100% 50%; }
}
.tab-container ul li:not(.selected):hover {
background: rgba(255, 255, 255, 0.15);
color: #fff;
transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.tab-container .tab-content {
display: none;
padding: 32px;
min-height: 180px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
color: rgba(255, 255, 255, 0.9);
border-radius: 0 0 16px 16px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-top: none;
position: relative;
overflow: hidden;
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.tab-container .tab-content::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(135deg,
rgba(255, 255, 255, 0.05) 0%,
rgba(255, 255, 255, 0.02) 50%,
rgba(255, 255, 255, 0.05) 100%);
pointer-events: none;
}
.tab-container .tab-content.selected {
display: block;
animation: glassFadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes glassFadeIn {
from {
opacity: 0;
transform: translateY(-20px) scale(0.95);
backdrop-filter: blur(10px);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
backdrop-filter: blur(20px);
}
}
JavaScript
// Get tab container
const tabContainer = document.querySelector('.tab-container');
const tabMenuItems = tabContainer.querySelectorAll('ul li');
const tabContents = tabContainer.querySelectorAll('.tab-content');
// Set event listeners for each tab menu item
tabMenuItems.forEach(tabMenuItem => {
tabMenuItem.addEventListener('click', () => {
// Remove selected class from all tabs
tabMenuItems.forEach(item => {
item.classList.remove('selected');
});
// Add selected class only to clicked tab
tabMenuItem.classList.add('selected');
// Remove selected class from all tab contents
tabContents.forEach(tabContent => {
tabContent.classList.remove('selected');
});
// Add selected class to content with same ID as clicked tab's data attribute
document.getElementById(tabMenuItem.dataset.id).classList.add('selected');
});
});