Modern Dialog
This is a modern design dialog box. The header and body are separated, with an X button in the top right corner.
HTML
<div class="container">
<button class="dialog-btn">Modern<br>Dialog</button>
</div>
<!-- Dialog Window -->
<div class="dialog">
<div class="dialog-content">
<div class="dialog-header">
<span class="dialog-title">Modern Dialog</span>
<button class="close-btn-x">×</button>
</div>
<div class="dialog-body">
<p>This is a modern design dialog box. The header and body are separated, with an X button in the top right corner.</p>
</div>
<div class="dialog-footer">
<button class="btn-primary">OK</button>
</div>
</div>
</div>
CSS
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
text-align: center;
margin: 50px auto;
}
.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 {
background-color: white;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
overflow: hidden;
width: 80%;
max-width: 500px;
margin: 8% auto;
animation: slideInFromTop 0.2s ease-out;
}
.dialog-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.dialog-title {
font-size: 18px;
font-weight: 600;
}
.close-btn-x {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: background-color 0.3s;
}
.close-btn-x:hover {
background-color: rgba(255, 255, 255, 0.2);
}
.dialog-body {
padding: 20px;
}
.dialog-body p {
margin: 0;
line-height: 1.6;
color: #555;
}
.dialog-footer {
padding: 20px;
text-align: center;
border-top: 1px solid #e9ecef;
}
.btn-primary {
background-color: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
}
.btn-primary:hover {
background-color: #0056b3;
}
@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;
}
.dialog-title {
font-size: 16px;
}
.dialog-body p {
font-size: 14px;
}
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
const dialogBtn = document.querySelector('.dialog-btn');
const dialog = document.querySelector('.dialog');
const closeBtn = document.querySelector('.close-btn-x');
const okBtn = document.querySelector('.btn-primary');
dialogBtn.addEventListener('click', function() {
dialog.style.display = 'block';
document.body.style.overflow = 'hidden';
});
function closeDialog() {
dialog.style.display = 'none';
document.body.style.overflow = 'auto';
}
closeBtn.addEventListener('click', closeDialog);
okBtn.addEventListener('click', closeDialog);
});