JSFiddle - React, Tailwind, and code Playground
by rohanbhangui
HTML
<div id="overlay">
<div id="overlayContent">
Overlay content here <br>
<a id="close" href="#">this button closes overlay it can be made image too</a>
</div>
</div>
<div id="content">Lorem ipsum dolor sit amet, consectetur adipisicing 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<a id="click" href=" # ">click to open overlay.</a>
</div>
CSS
#overlay {
position: absolute;
background: rgba(0, 0, 0, 0.5);
width: 99%;
height: 98%;
z-index: 100;
display: none;
}
#overlayContent {
position: absolute;
width: 200px;
height: 200px;
background: #fff;
top: 50%;
left: 50%;
margin-left: -100px; /* this is the negative value of half of the width */
margin-top: -100px; /* this is the negative value of half of the height */
}
#content {
position: absolute;
z-index: 0;
}
JavaScript
$("#click").on("click", function () {
$("#overlay").fadeIn(300);
});
$("#close").on("click", function () {
$("#overlay").fadeOut(300);
});