JSFiddle - React, Tailwind, and code Playground
by Milan Karagunović
HTML
<article>
<h4>Click me</h4>
</article>
CSS
article {
background: #fff;
position: absolute;
width: 240px;
height: 190px;
top: 50%;
left: 50%;
margin-top: -105px;
margin-left: -130px;
padding: 10px;
z-index: 9999;
line-height: 140px;
text-align: center;
border: 1px solid #ddd;
}
.overlay {
background: rgba(50,50,50,0.5);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
JavaScript
(function($) {
$('article').on('click', function() {
if($('.overlay').length < 1) {
$('body').append('<span class="overlay"></span>');
}
});
$(document).on('click','.overlay', function() {
$('.overlay').remove();
});
})(jQuery);