ダイアログボックス:マテリアルデザイン|Dialog Box: Material Design

Material Design Dialog

This dialog follows Material Design principles with proper elevation, typography, and interaction patterns.

HTML
<div class="container">
    <div id="dialog-container">
        <button id="dialog-btn">Material Design<br>Dialog</button>     
    </div>

    <!-- Dialog Window -->
    <div id="dialog" class="dialog">
        <div class="dialog-content">
            <div class="material-header">
                <span>Material Design Dialog</span>
                <button class="material-close-btn">×</button>
            </div>
            <div class="material-body">
                <p>This dialog follows Material Design principles with proper elevation, typography, and interaction patterns.</p>
            </div>
            <div class="material-footer">
                <button class="material-btn-text">Cancel</button>
                <button class="material-btn-contained">Accept</button>
            </div>
        </div>
    </div>
</div>
CSS
/* ダイアログコンテナスタイル */
#dialog-container {
    text-align: center;
    padding: 50px 20px;
}

/* ダイアログボタンスタイル */
#dialog-btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.3s ease;
    min-width: 200px;
    min-height: 60px;
    display: inline-block;
    text-align: center;
    line-height: 1.4;
    vertical-align: middle;
}

#dialog-btn:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

/* ダイアログオーバーレイスタイル */
.dialog {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

/* ダイアログコンテンツスタイル */
.dialog-content {
    width: 80%;
    max-width: 400px;
    margin: 8% auto;
    animation: slideInFromTop 0.2s ease-out;
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 
        0 14px 28px rgba(0, 0, 0, 0.25),
        0 10px 10px rgba(0, 0, 0, 0.22);
    overflow: hidden;
    animation: materialSlideIn 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    border: none;
    position: relative;
}

.dialog-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
    pointer-events: none;
    z-index: 1;
}

@keyframes materialSlideIn {
    0% {
        transform: scale(0.8) translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* マテリアルヘッダー */
.material-header {
    background: #2196f3;
    color: white;
    padding: 24px 24px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    z-index: 2;
}

.material-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.12);
}

.material-header span {
    font-size: 20px;
    font-weight: 400;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: 0.15px;
    line-height: 1.4;
    margin: 0;
    flex: 1;
}

.material-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    position: relative;
    overflow: hidden;
    margin-left: 8px;
}

.material-close-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.material-close-btn:hover::before {
    width: 40px;
    height: 40px;
}

.material-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.material-close-btn:active {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

/* マテリアルボディ */
.material-body {
    padding: 20px 24px 24px;
    background: #ffffff;
    position: relative;
    z-index: 2;
}

.material-body p {
    margin: 0;
    line-height: 1.6;
    color: rgba(0, 0, 0, 0.87);
    font-size: 16px;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 400;
    letter-spacing: 0.15px;
}

/* マテリアルフッター */
.material-footer {
    padding: 8px 8px 8px 24px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    background: #ffffff;
    position: relative;
    z-index: 2;
    min-height: 52px;
    align-items: center;
}

.material-btn-text {
    background: none;
    color: #2196f3;
    border: none;
    padding: 0 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    min-width: 64px;
    height: 36px;
    position: relative;
    overflow: hidden;
}

.material-btn-text::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(33, 150, 243, 0.12);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.material-btn-text:hover::before {
    width: 100px;
    height: 100px;
}

.material-btn-text:hover {
    background-color: rgba(33, 150, 243, 0.04);
}

.material-btn-text:active {
    background-color: rgba(33, 150, 243, 0.08);
    transform: scale(0.98);
}

.material-btn-contained {
    background: #2196f3;
    color: white;
    border: none;
    padding: 0 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    min-width: 64px;
    height: 36px;
    box-shadow: 
        0 3px 1px -2px rgba(0, 0, 0, 0.2),
        0 2px 2px 0 rgba(0, 0, 0, 0.14),
        0 1px 5px 0 rgba(0, 0, 0, 0.12);
    position: relative;
    overflow: hidden;
}

.material-btn-contained::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.material-btn-contained:hover::before {
    width: 100px;
    height: 100px;
}

.material-btn-contained:hover {
    background: #1976d2;
    box-shadow: 
        0 2px 4px -1px rgba(0, 0, 0, 0.2),
        0 4px 5px 0 rgba(0, 0, 0, 0.14),
        0 1px 10px 0 rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.material-btn-contained:active {
    background: #0d47a1;
    box-shadow: 
        0 5px 5px -3px rgba(0, 0, 0, 0.2),
        0 8px 10px 1px rgba(0, 0, 0, 0.14),
        0 3px 14px 2px rgba(0, 0, 0, 0.12);
    transform: translateY(0);
}

/* マテリアルデザインのフォーカス状態 */
.material-btn-text:focus,
.material-btn-contained:focus,
.material-close-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.3);
}

.material-btn-text:focus {
    background-color: rgba(33, 150, 243, 0.08);
}

.material-btn-contained:focus {
    background: #1976d2;
    box-shadow: 
        0 2px 4px -1px rgba(0, 0, 0, 0.2),
        0 4px 5px 0 rgba(0, 0, 0, 0.14),
        0 1px 10px 0 rgba(0, 0, 0, 0.12),
        0 0 0 2px rgba(33, 150, 243, 0.3);
}

/* アニメーション */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInFromTop {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .dialog-content {
        width: 90%;
        margin: 15% auto;
        padding: 15px;
    }
    
    .material-header span {
        font-size: 16px;
    }
    
    .material-body p {
        font-size: 14px;
    }
}
JavaScript
// マテリアルデザインダイアログの機能
document.addEventListener('DOMContentLoaded', function() {
    // ダイアログボタンのイベントリスナーを設定
    const dialogBtn = document.getElementById('dialog-btn');
    const dialog = document.getElementById('dialog');
    
    dialogBtn.addEventListener('click', function() {
        dialog.style.display = 'block';
        // スクロールを無効化
        document.body.style.overflow = 'hidden';
    });
    
    // 閉じるボタンのイベントリスナーを設定
    const closeButtons = document.querySelectorAll('.material-btn-text, .material-btn-contained, .material-close-btn');
    
    closeButtons.forEach(button => {
        button.addEventListener('click', function() {
            dialog.style.display = 'none';
            // スクロールを有効化
            document.body.style.overflow = 'auto';
        });
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次