As you said that a CSS-only answer could answer you, here I will leave a technique. The principle here is that btn Close is actually a label
linked in a input:radio
that when checkado
does the div
that comes down go away .
Notice that I put a small delay on the modal input, but on animation
you can control this value whether it takes longer or not. Notice that when the modal is active you can not select anything that is below, or click anything (this is for the lay user).
I tried to make the template as simple as possible to make it easier to understand. I left comments in the code.
See the example.
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#rd {
display: none;
}
input[id="rd"]:checked + div.bg {
display: none;
z-index: -1000;
opacity: 0;
}
.bg {
position: fixed;
top: 0;
left: 0;
z-index: 100;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
/* remover animação se quiser que ele aparece direto sem delay */
-webkit-animation: tempo 500ms ease-in 250ms forwards;
animation: tempo 500ms ease-in 250ms forwards;
}
.box {
background-color: red;
width: 100px;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.box label {
background-color: #fff;
width: 50px;
height: 30px;
line-height: 30px;
text-align: center;
display: inline-block;
cursor: pointer;
}
/* remover se remover a animação do modal */
@-webkit-keyframes tempo {
to {
opacity: 1;
}
}
@keyframes tempo {
to {
opacity: 1;
}
}
<!-- modal -->
<input type="radio" id="rd">
<div class="bg">
<div class="box">
<label for="rd">fechar</label>
</div>
</div>
<!-- conteudo de Exemplo -->
<table border="1">
<tr>
<td>100px</td>
<td>200px</td>
</tr>
</table>
<input type="submit">
<input type="text">