Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML & CSS to create and implement a single modal, where the button and css are linked by a static string name.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<style> | ||
.modal { | ||
display: none; /* Hidden by default */ | ||
position: fixed; /* Stay in place */ | ||
z-index: 1; /* Sit on top */ | ||
padding-top: 100px; /* Location of the box */ | ||
left: 4px; */ top: 8px; | ||
width: 80%; /* Full width */ height: 100%; /* Full height */ | ||
overflow: auto; /* Enable scroll if needed */ | ||
background-color: rgb(0,0,0); /* Fallback color */ | ||
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ | ||
} | ||
|
||
/* Modal Content */ | ||
.modal-content { background-color: #fefefe; margin: 5px; font-size: 80%; padding: 5px; border: 1px solid #888; | ||
width: 80%;} | ||
/* The Close Button */ | ||
.close { color: #aaaaaa; float: right; font-size: 28px; font-weight: bold; } | ||
.close:hover, .close:focus { color: #000; text-decoration: none; cursor: pointer; } | ||
|
||
.scroll-box { | ||
width: 650px; /* maximum width of the box, feel free to change this! */ | ||
overflow-x: scroll; white-space: nowrap; } | ||
</style> | ||
|
||
|
||
<button id="myBtn">Lorem Ipsom ...</button> | ||
<div id="myModal" class="modal"> | ||
<p><!-- Modal content --></p> | ||
<div class="modal-content" style="width: 100%;"> | ||
<p><span class="close">×</span></p> | ||
<p style="font-size: 120%;">An example modal</p> | ||
<p style="font-size: 102%;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
// Get the modal | ||
var modal = document.getElementById("myModal"); | ||
|
||
// Get the button that opens the modal | ||
var btn = document.getElementById("myBtn"); | ||
|
||
// Get the <span> element that closes the modal | ||
var span = document.getElementsByClassName("close")[0]; | ||
|
||
// When the user clicks on the button, open the modal | ||
btn.onclick = function() { | ||
modal.style.display = "block"; | ||
} | ||
|
||
// When the user clicks on <span> (x), close the modal | ||
span.onclick = function() { | ||
modal.style.display = "none"; | ||
} | ||
|
||
// When the user clicks anywhere outside of the modal, close it | ||
window.onclick = function(event) { | ||
if (event.target == modal) { | ||
modal.style.display = "none"; | ||
} | ||
} | ||
</script> |