← 一覧へ

Dialog / 13 マテリアルデザイン|Material Design

デザイン見本

Material Design Dialog

Google Material Design準拠のダイアログボックスです。

Google Material Design準拠のダイアログボックスです。

実装コード

HTML
<button id="dialog-btn-13">Material Design<br>Dialog</button>
                <div id="dialog-13" class="dialog">
                    <div class="dialog-content">
                        <div class="material-header">
                            <span>Material Design Dialog</span>
                            <button class="material-close-btn">&times;</button>
                        </div>
                        <div class="material-body">
                            <p>Google Material Design準拠のダイアログボックスです。</p>
                        </div>
                        <div class="material-footer">
                            <button class="material-btn-text">Cancel</button>
                            <button class="material-btn-contained">Accept</button>
                        </div>
                    </div>
                </div>
CSS
#dialog-btn-13 {
    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-13:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

#dialog-13 {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    border: none;
    padding: 0;
    box-sizing: border-box;
    animation: fadeIn-13 0.3s;
}

#dialog-13 .dialog-content {
    width: 80%;
    max-width: 400px;
    margin: 8% auto;
    animation: slideInFromTop-13 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-13 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    border: none;
    position: relative;
}

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

#dialog-13 .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;
}

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

#dialog-13 .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;
}

#dialog-13 .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;
}

#dialog-13 .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;
}

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

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

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

#dialog-13 .material-body {
    padding: 20px 24px 24px;
    background: #ffffff;
    position: relative;
    z-index: 2;
}

#dialog-13 .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;
}

#dialog-13 .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;
}

#dialog-13 .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;
}

#dialog-13 .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;
}

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

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

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

#dialog-13 .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;
}

#dialog-13 .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;
}

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

#dialog-13 .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);
}

#dialog-13 .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);
}

#dialog-13 .material-btn-text:focus,
#dialog-13 .material-btn-contained:focus,
#dialog-13 .material-close-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.3);
}

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

#dialog-13 .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-13 {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@media (max-width: 768px) {
    #dialog-13 .dialog-content {
        width: 90%;
        margin: 15% auto;
        padding: 15px;
    }

    #dialog-13 .material-header span {
        font-size: 16px;
    }

    #dialog-13 .material-body p {
        font-size: 14px;
    }
}
JS
(function () {
      var btn = document.getElementById('dialog-btn-13');
      var dialog = document.getElementById('dialog-13');
      var closeBtns = dialog ? dialog.querySelectorAll('button') : [];

      if (!btn || !dialog) return;

      function openDialog() {
        dialog.style.display = 'block';
        document.body.style.overflow = 'hidden';
      }

      function closeDialog() {
        dialog.style.display = 'none';
        document.body.style.overflow = 'auto';
      }

      btn.addEventListener('click', openDialog);
      
      closeBtns.forEach(function(b) { b.addEventListener('click', closeDialog); });

      dialog.addEventListener('click', function (e) {
        if (e.target === dialog) {
          closeDialog();
        }
      });

      document.addEventListener('keydown', function (e) {
        if (e.key === 'Escape' && dialog.style.display === 'block') {
          closeDialog();
        }
      });
    })();