← 一覧へ

Tab Menu / 31 チョーク黒板|Chalkboard

デザイン見本

  • 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.

黒板をイメージしたシックなデザインです。選択タブの下に引かれる白いラインが `scaleX(0→1)` で左から右へ描かれるアニメーションが特徴で、まるでチョークで線を引いているような演出になります。木枠の外枠と黒板グリーンの背景が独特の雰囲気を醸し出します。

実装コード

HTML
<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>
CSS
.tab-container {
    background: #2b3a2e;
    border: 4px solid #5a4832;
    border-radius: 4px;
    box-shadow:
        inset 0 0 80px rgba(0, 0, 0, 0.25),
        0 4px 16px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.tab-container ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    background: #1e2b21;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.tab-container ul li {
    flex: 1;
    padding: 16px 12px;
    text-align: center;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.4);
    font-size: 14px;
    letter-spacing: 1.5px;
    position: relative;
    transition: color 0.3s ease;
}

.tab-container ul li::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 15%;
    width: 70%;
    height: 2px;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.4);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.4s ease;
    border-radius: 1px;
}

.tab-container ul li.selected {
    color: rgba(255, 255, 255, 0.95);
    text-shadow:
        0 0 12px rgba(255, 255, 255, 0.4),
        1px 1px 2px rgba(0, 0, 0, 0.3);
}

.tab-container ul li.selected::after {
    transform: scaleX(1);
}

.tab-container ul li:not(.selected):hover {
    color: rgba(255, 255, 255, 0.65);
}

.tab-container .tab-content {
    display: none;
    padding: 28px 24px;
    min-height: 150px;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.8;
    font-size: 14px;
    letter-spacing: 0.3px;
    position: relative;
    background-image:
        radial-gradient(circle at 15% 25%, rgba(255, 255, 255, 0.03) 0%, transparent 60%),
        radial-gradient(circle at 85% 75%, rgba(255, 255, 255, 0.02) 0%, transparent 60%);
}

.tab-container .tab-content::before {
    content: '';
    position: absolute;
    top: 12px;
    left: 16px;
    right: 16px;
    bottom: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    pointer-events: none;
}

.tab-container .tab-content.selected {
    display: block;
    animation: chalkIn 0.45s ease-out;
}

@keyframes chalkIn {
    from { opacity: 0; transform: translateY(-8px); filter: blur(1px); }
    to { opacity: 1; transform: translateY(0); filter: blur(0); }
}
JS
(function () {
    'use strict';
    document.addEventListener('DOMContentLoaded', function () {
        var container = document.querySelector('.tab-container');
        if (!container) return;
        var items = container.querySelectorAll('ul li');
        var contents = container.querySelectorAll('.tab-content');

        items.forEach(function (item) {
            item.addEventListener('click', function () {
                items.forEach(function (i) { i.classList.remove('selected'); });
                contents.forEach(function (c) { c.classList.remove('selected'); });
                item.classList.add('selected');
                var target = document.getElementById(item.getAttribute('data-id'));
                if (target) target.classList.add('selected');
            });
        });
    });
})();