Last active
June 5, 2020 13:29
-
-
Save dfar-io/30cc8addd95ce35eb05acf3dd45ffded to your computer and use it in GitHub Desktop.
Provides a link to JSFiddle with vertically centered modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Can be found at https://jsfiddle.net/jkem8nsz/49/ | |
// HTML | |
<a href="#" id="text"> | |
click to show modal<br > | |
</a> | |
<div id="modal" class="modal-outer"> | |
<div class="modal-middle"> | |
<div class="modal-inner"> | |
<h1>The Content</h1> | |
<p>Once upon a midnight dreary...</p> | |
</div> | |
</div> | |
</div> | |
// JS | |
document.getElementById("text").addEventListener("click", function() { | |
var modal = document.getElementById("modal"); | |
modal.style.display = "table"; | |
}); | |
// CSS | |
.modal-outer { | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 100%; | |
width: 100%; | |
/* dim outside of modal */ | |
background-color: rgba(0,0,0,0.8); | |
/* initially hide*/ | |
display: none; | |
} | |
.modal-middle { | |
display: table-cell; | |
vertical-align: middle; | |
} | |
.modal-inner { | |
margin-left: auto; | |
margin-right: auto; | |
/* set width based on what you'd like */ | |
width: 400px; | |
/* customizations */ | |
border: 1px solid black; | |
padding: 1rem; | |
background-color: white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment