タブメニュー:ボタン風|Tab Menu: Button Style

  • 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 Menu - Rounded Button Style</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
.container {
    max-width: 800px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
}

.tab-container {
    overflow: hidden;
    border-radius: 12px;
    position: relative;
    background: #f8f9fa;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.tab-container ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    position: relative;
}

.tab-container ul li {
    flex: 1;
    padding: 14px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    color: #666;
    font-weight: 500;
    font-family: 'Arial', sans-serif;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(0);
}

.tab-container ul li.selected {
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
}

.tab-container ul li:not(.selected):hover {
    background: #f8f9fa;
    border-color: #667eea;
    color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(102, 126, 234, 0.2);
}

.tab-content {
    display: none;
    padding: 24px;
    min-height: 150px;
    background: #fff;
    color: #333;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
}

.tab-content.selected {
    display: block;
    animation: buttonFadeIn 0.4s ease;
}

@keyframes buttonFadeIn {
    from { 
        opacity: 0; 
        transform: translateY(-10px) scale(0.95);
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1);
    }
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
    const tabMenuItems = document.querySelectorAll('.tab-container ul li');
    const tabContents = document.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');
        });
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次