"Untitled"
Bootstrap 4.1.1 Snippet by asimkassab

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <button id="modalBtn" class="button">click Here</button> <div id="simpleModal" class="modal"> <div class="modal-content"> <span class="closeBtn">×</span> <p>Hello..... Iam a modal</p> </div> </div> <script src="main.js"></script>
body{ font-size: 17px; line-height: 1.6; } .button{ background: coral; padding: 1em 2em; color: #fff; border: 0; } .button:hover{ background: #333; } .modal{ display: none; position: fixed; z-index: 1; left: 0; top: 0; height: 100%; width: 100%; overflow: auto; background-color: rgba(0,0,0,0.5); } .modal-content{ background-color: #f4f4f4; margin: 20%; padding: 20px; box-shadow: 0 5px 0 rgba(0,0,0,0.2),0 7px 20px 0 rgba(0,0,0,0.17); } .closeBtn{ color: #ccc; float: right; font-size: 30px; } .closeBtn:hover ,.closeBtn:focus{ color: #000; text-decoration: none; cursor: pointer; }
//get the modal element var modal = document.getElementById('simpleModal'); //get open modal button var modalBtn = document.getElementById('modalBtn'); // get close button var closeBtn = document.getElementsByClassName('closeBtn')[0]; // listen foe open click modalBtn.addEventListener('click', openModal); // listen foe close click closeBtn.addEventListener('click', closeModal); // listen foe close click window.addEventListener('click', outsideClick); //Function to open modal function openModal(){ modal.style.display = 'block'; } //Function to close modal function closeModal(){ modal.style.display = 'none'; } //Function to close modal function outsideClick(e){ if (e.target == modal) { modal.style.display = 'none'; } }

Related: See More


Questions / Comments: