<h1>Simple Responsive Modal</h1>
<button>Click For Modal</button>
<!-- modal -->
<div class="modal-overlay">
<div class="modal">
<a class="close-modal">
<svg viewBox="0 0 20 20">
<path fill="#000000" d="M15.898,4.045c-0.271-0.272-0.713-0.272-0.986,0l-4.71,4.711L5.493,4.045c-0.272-0.272-0.714-0.272-0.986,0s-0.272,0.714,0,0.986l4.709,4.711l-4.71,4.711c-0.272,0.271-0.272,0.713,0,0.986c0.136,0.136,0.314,0.203,0.492,0.203c0.179,0,0.357-0.067,0.493-0.203l4.711-4.711l4.71,4.711c0.137,0.136,0.314,0.203,0.494,0.203c0.178,0,0.355-0.067,0.492-0.203c0.273-0.273,0.273-0.715,0-0.986l-4.711-4.711l4.711-4.711C16.172,4.759,16.172,4.317,15.898,4.045z"></path>
</svg>
</a><!-- close modal -->
<div class="modal-content">
<h3>Some content here</h3>
</div><!-- content -->
</div><!-- modal -->
</div><!-- overlay -->
/**
* Variables
*/
$button-bg: #0D52E9;
$speed: 0.6s;
$delay: ($speed * .5);
$easing: cubic-bezier(.55,0,.1,1);
/**
* Base styles
*/
body,
html {
background: #080616;
font-family: 'Roboto', sans-serif;
text-align: center;
}
h1, h2, h3, h4, h5, h6 {
font-weight: normal;
}
h1 {
font-size: 1.875rem;
font-weight: 300;
margin: 60px 0 30px 0;
color: #fff;
}
button {
background-color: $button-bg;
position: relative;
color: #fff;
border: none;
padding: 1.25em 2em;
font-size: 0.75em;
letter-spacing: 1px;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 10px 20px rgba(0,0,0,.1);
transition: background 0.25s $easing;
&:hover {
background: darken($button-bg, 3%);
}
&:focus {
outline: none;
}
}
/**
* Overlay
* -- only show for tablet and up
*/
@media only screen and (min-width: 40em) {
.modal-overlay {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 5;
background-color: rgba(#000, 0.6);
opacity: 0;
visibility: hidden;
backface-visibility: hidden;
transition: opacity $speed $easing, visibility $speed $easing;
&.active {
opacity: 1;
visibility: visible;
}
}
} // media query
/**
* Modal
*/
.modal {
display: flex;
align-items: center;
justify-content: center;
position: relative;
margin: 0 auto;
background-color: #fff;
width: 600px;
max-width: 75rem;
min-height: 20rem;
padding: 1rem;
border-radius: 3px;
opacity: 0;
overflow-y: auto;
visibility: hidden;
box-shadow: 0 2px 10px rgba(#000, 0.1);
backface-visibility: hidden;
transform: scale(1.2);
transition: all $speed $easing;
.close-modal {
position: absolute;
cursor: pointer;
top: 5px;
right: 15px;
opacity: 0;
backface-visibility: hidden;
transition: opacity $speed $easing, transform $speed $easing;
transition-delay: $delay;
svg {
width: 1.75em;
height: 1.75em;
}
} // close modal
.modal-content {
opacity: 0;
backface-visibility: hidden;
transition: opacity $speed $easing;
transition-delay: $delay;
} // content
&.active {
visibility: visible;
opacity: 1;
transform: scale(1);
.modal-content {
opacity: 1;
}
.close-modal {
transform: translateY(10px);
opacity: 1;
}
}
}
/**
* Mobile styling
*/
@media only screen and (max-width: 39.9375em) {
h1 {
font-size: 1.5rem;
}
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow-scrolling: touch;
border-radius: 0;
transform: scale(1.1);
padding: 0 !important;
}
.close-modal {
right: 20px !important;
}
} // media query
View Compiled
var elements = $('.modal-overlay, .modal');
$('button').click(function(){
elements.addClass('active');
});
$('.close-modal').click(function(){
elements.removeClass('active');
});
This Pen doesn't use any external CSS resources.