DEV Community

Discussion on: Creating a CSS modal window (pop-up) step-by-step

Collapse
 
utterhuman profile image
Serge Paskal • Edited

Great article.
I didn't know neither about :target (supports from Chrome 1) nor <dialog> 🤦 shame on me.
Speaking about the code, just noticed your modal behaves different than the one from MDN: click to grey area doesn't close the popup (::backdrop in case of dialog element). Styling .modal__close:before, .modal__close:after (with z-index) and moving .modal__close itself to #modal's children level do the trick.

Collapse
 
supersmartat profile image
Andreas Huber

If anyone needs a quickfix - i used the onclick to fix this background closing. It not plain css of course, but it improves usability for my application:

I extended the same logic with
<div id="modal" onclick="location.href='#'"; >
finally the grey background closes like the X before.