タブメニュー:グラデーション|Tab Menu: Gradient

  • 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 4 - Gradient</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
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
}

h1 {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin: 0;
}

/* ===== Design 4: Gradient ===== */
.tab-container ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    background: linear-gradient(45deg, #667eea, #764ba2);
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    position: relative;
}

.tab-container ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.tab-container ul li {
    flex: 1;
    padding: 16px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    color: rgba(255,255,255,0.8);
    border-right: 1px solid rgba(255,255,255,0.2);
}

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

.tab-container ul li.selected {
    color: #fff;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    font-weight: bold;
}

.tab-container ul li:not(.selected):hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.tab-container .tab-content {
    display: none;
    padding: 24px;
    min-height: 150px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.tab-container .tab-content.selected {
    display: block;
}
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');
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次