Modal jen pomocí css a html summary
by Petr Haluza
HTML
<div class="container">
<details>
<summary>
<div class="button">Jsem jakože tlačítko</div>
<div class="details-modal-overlay"></div>
</summary>
<div class="details-modal">
<div class="details-modal-close">x</div>
<div class="details-modal-title">
<h1>Jsem jakože modal</h1>
</div>
<div class="details-modal-content">
<p>Blah blah a zacvřu se klikem kamkoliv jinam, nebo na křížek</p>
</div>
</div>
</details>
</div>
CSS
*,
*:before,
*:after {
box-sizing: border-box;
}
.button { background: #16a34a; color: white; padding: 1em;}
.details-modal {
background: #ffffff;
border-radius: 0.5em;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
left: 50%;
max-width: 90%;
pointer-events: none;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: 30em;
text-align: left;
max-height: 90vh;
display: flex;
flex-direction: column;
}
.details-modal .details-modal-close {
align-items: center;
display: flex;
height: 4.5em;
justify-content: center;
pointer-events: none;
position: absolute;
right: 0;
top: 0;
width: 4.5em;
}
.details-modal .details-modal-title {
color: #111827;
padding: 1.5em 2em;
pointer-events: all;
position: relative;
width: calc(100% - 4.5em);
}
.details-modal .details-modal-content {
border-top: 1px solid #e0e0e0;
padding: 2em;
pointer-events: all;
overflow: auto;
}
.details-modal-overlay {
transition: opacity 0.2s ease-out;
pointer-events: none;
background: rgba(15, 23, 42, 0.8);
position: fixed;
opacity: 0;
bottom: 0;
right: 0;
left: 0;
top: 0;
}
details[open] .details-modal-overlay {
pointer-events: all;
opacity: 0.5;
}
details > summary {
list-style-type: none;
}
details > summary::-webkit-details-marker {
display: none;
}
details > summary::before {
content: '?';
}
details[open] > summary::before {
content: 'x';
}