<main>
<button class="button" data-title="Good job!" data-msg="You clicked the button.">modal-window</button>
</main>
<div class="modal">
<article class="modal__article">
<h4 class="modal-title"></h4>
<p class="modal-msg"></p>
</article>
<footer>
<button class="button -full -close">close</button>
</footer>
</div>
.modal {
width: 24rem;
color: #33465E;
background-color: white;
position: fixed;
top: -50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 1rem rgba(black, 0.1);
opacity: 0;
transition: opacity 550ms ease-in-out;
&__article {
text-align: center;
padding: 2.5rem;
.modal-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.75rem;
}
}
&__footer {
width: 100%;
height: 3rem;
}
&.in {
opacity: 1;
top: 50%;
}
}
.button {
font-weight: bold;
color: #fff;
padding: 15px 35px;
border: 2px solid #fff;
transition: all 250ms ease-in-out;
&:hover {
color: #fff;
background-color: HSLA(0, 0%, 100%, .2);
}
&.-full {
background-color: #33465E;
width: 100%;
height: 100%;
}
}
main {
width: 100vw;
height: 100vh;
color: #E0DEDE;
background: linear-gradient(-90deg, #8DABD6, #95BFD6, #8DABD6);
font-size: 1.1rem;
display: flex;
align-items: center;
justify-content: center;
}
View Compiled
var Modal = (function() {
var modalOpen = function() {
var title = $(this).data('title');
var msg = $(this).data('msg');
$('.modal-title').text(title);
$('.modal-msg').text(msg);
$('.modal').addClass('in');
};
var modalClose = function() {
$('.modal').removeClass('in');
};
$('.button').click(modalOpen);
$('.-close').click(modalClose);
})();