Usage
Modals are notoriously difficult to accomplish with pure CSS. There are two ways of adding popup functionality,
one through the :target selector, the other the checkbox
method.
We have opted to create our modals via the checkbox technique as having empty links on a page can hinder
your SEO efforts.
Of course if you prefer to use vanilla JS for modals, there is a simple script you can you use at the bottom
of this page.
Notation:
- There needs to be an action button & checkbox that links to the modal in order for it to appear.
- To achieve this, add a
<label>element with aforattribute. Then create a checkbox with the classmodal-toggleand set the ID the same as theforattribute of the label. - If you wish to add multiple close buttons, just simply add more labels with the
forattribute set equal to the ID of the checkbox. - The modal comprises of a
modal-containerto wrap the modal content, amodal-headerfor the title & close button, themodal-bodyfor the main content & themodal-footerfor action buttons. - The
modal-overlayis entirely optional, if you wish to disable the close functionality, simply change the<label>to a<div>
<label for="exampleModal" class="btn btn-secondary c-white">Centered</label> <input type="checkbox" class="modal-toggle" id="exampleModal"> <div class="modal" aria-hidden="true"> <div class="modal-container"> <div class="modal-header"> <h3>Modal Title</h3> <label class="modal-btn-close" for="exampleModal"> <i class="fas fa-times"></i> </label> </div> <div class="modal-body"> <p>An old man walked across the beach...</p> </div> <div class="modal-footer"> <button class="btn mr-2 btn-primary">Nice Story!</button> <label for="exampleModal" class="btn btn-secondary">Close</label> </div> </div> <label for="exampleModal" class="modal-overlay"></label> </div>