タブメニュー:丸ボタン|Tab Menu: Circle Button

  • 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 16: 丸ボタン風</h1>
    
    <div class="tab-container tab-design">
        <ul>
            <li class="selected" data-id="tab-16-1">Tab 1</li>
            <li data-id="tab-16-2">Tab 2</li>
            <li data-id="tab-16-3">Tab 3</li>
        </ul>
        <div class="tab-content selected" id="tab-16-1">
            Good morning. This is the content of Tab 1.
        </div>
        <div class="tab-content" id="tab-16-2">
            Hello. This is the content of Tab 2.
        </div>
        <div class="tab-content" id="tab-16-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: 20px;
    position: relative;
    background: #f8f9fa;
    padding: 30px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tab-design ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    position: relative;
}

.tab-design ul li {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    color: #666;
    font-weight: 600;
    font-size: 14px;
    background: #fff;
    border: 3px solid #e0e0e0;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    overflow: hidden;
}

.tab-design ul li::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    transform: scale(0);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: -1;
}

.tab-design ul li.selected {
    color: #fff;
    border-color: #667eea;
    box-shadow: 
        0 8px 24px rgba(102, 126, 234, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
    transform: translateY(-4px) scale(1.05);
}

.tab-design ul li.selected::before {
    transform: scale(1);
}

.tab-design ul li:not(.selected):hover {
    border-color: #667eea;
    color: #667eea;
    transform: translateY(-2px) scale(1.02);
    box-shadow: 
        0 6px 20px rgba(102, 126, 234, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tab-design .tab-content {
    display: none;
    padding: 30px;
    min-height: 180px;
    background: #fff;
    color: #333;
    border-radius: 16px;
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    overflow: hidden;
}

.tab-design .tab-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 16px 16px 0 0;
}

.tab-design .tab-content.selected {
    display: block;
    animation: circleButtonFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes circleButtonFadeIn {
    from { 
        opacity: 0; 
        transform: translateY(-20px) scale(0.95);
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(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');
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次