How to make Pop-up Box model ?
| HTML | CSS | Javascript | OUTPUT |
|---|---|---|---|
<h1>Animated Modal with Header and Footer</h1>
<button id="myBtn">Open Modal</button>
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<span class="close">close</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
<div class="modal-footer">
<h3>Modal Footer</h3>
</div>
</div>
</div>
|
.modal {display: none; position: fixed; z-index: 1; padding-top: 100px; left: 0;
top: 0;width: 100%; height: 100%;overflow: auto; background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4); }
.modal-content {position: relative;background-color: #fefefe;margin: auto;
padding: 0; border: 1px solid #888;width: 40%;-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.5s; }
@-webkit-keyframes animatetop {from {top:-300px; opacity:0} to {top:0; opacity:1}}
@keyframes animatetop {from {top:-300px; opacity:0}to {top:0; opacity:1}}
.close {color: white;float: right;font-size: 20px;font-weight: bold;}
.close:hover,.close:focus {color: #000;text-decoration: none;cursor: pointer;}
.modal-header { padding: 2px 16px;background-color: #5cb85c;color: white;}
.modal-body {padding: 2px 16px;}
.modal-footer { padding: 2px 16px;background-color: #5cb85c; color: white;}
#myBtn{background-color:cornflowerblue; padding:15px 20px; border-radius:25px;}
|
var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function () {
modal.style.display = "block";
}
span.onclick = function () {
modal.style.display = "none";
}
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
|
Animated Modal with
|
Last Update: July 9, 2026
Total 0 Votes:
0
0

