Dialog Title
This is a sample of a simple dialog box. It is based on the functionality and design of JavaScript’s alert().
HTML
<div class="container">
<button class="dialog-btn">Simple<br>Dialog</button>
</div>
<!-- Dialog Window -->
<div class="dialog">
<div class="dialog-content">
<p>Dialog Title</p>
<p>This is a sample of a simple dialog box. It is based on the functionality and design of JavaScript's alert().</p>
<div class="close-btn-container">
<button class="close-btn">Close</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;
padding: 20px;
border: 1px solid #888;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
width: 80%;
max-width: 500px;
margin: 8% auto;
animation: slideInFromTop 0.2s ease-out;
}
.dialog-content p:first-child {
font-weight: bold;
font-size: 18px;
margin-bottom: 15px;
color: #333;
}
.dialog-content p:nth-child(2) {
margin-bottom: 20px;
line-height: 1.5;
color: #666;
}
.close-btn-container {
text-align: center;
}
.close-btn {
background-color: #6c757d;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
}
.close-btn:hover {
background-color: #545b62;
}
@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;
}
.dialog-content p:first-child {
font-size: 16px;
}
.dialog-content p:nth-child(2) {
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');
dialogBtn.addEventListener('click', function() {
dialog.style.display = 'block';
document.body.style.overflow = 'hidden';
});
closeBtn.addEventListener('click', function() {
dialog.style.display = 'none';
document.body.style.overflow = 'auto';
});
});