Skip to content

Instantly share code, notes, and snippets.

@WebJax
Created April 21, 2022 02:05
Show Gist options
  • Save WebJax/41fd6d3236ee3923bc417acdff953861 to your computer and use it in GitHub Desktop.
Save WebJax/41fd6d3236ee3923bc417acdff953861 to your computer and use it in GitHub Desktop.
Modal
<div class="modalbackground">
<div class="modal">
<div class="modal-close"></div>
<div class="modal-content">
<header>
<h1>This is the header</h1>
</header>
<section>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p><p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</section>
</div>
</div>
</div>
$('.modal-close').on('click', function() {
$('.modalbackground').hide();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
.modalbackground {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,.6);
}
.modal {
width: 50%;
height: 35%;
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: white;
border-radius: 4px;
box-shadow: 0px 0px 80px -20px black;
}
.modal-close {
position: absolute;
background-color: white;
padding: 4px;
border-radius: 50%;
right: -15px;
top: -15px;
width: 20px;
height: 20px;
box-shadow: 0 0 20px 0px black;
z-index: 2;
cursor: pointer;
transition: 200ms all;
transform: scale(1);
}
.modal-close:hover {
transform: scale(1.2);
}
.modal-close:after {
content: "X";
font-weight: 900;
position: relative;
left: 3px;
top: -1px;
font-size: 20px;
}
.modal-content {
overflow: scroll;
height: 100%;
}
.modal-content header {
background-color: #e9e9e9;
padding: 1px 20px;
position: fixed;
width: 93.5%;
z-index: 1;
box-shadow: 0 0 20px -5px black;
}
.modal-content header h1 {
text-transform: uppercase;
}
.modal-content section {
position: relative;
display: block;
top: 80px;
width: 90%;
left: 20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment