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 afor
attribute. Then create a checkbox with the classmodal-toggle
and set the ID the same as thefor
attribute of the label. - If you wish to add multiple close buttons, just simply add more labels with the
for
attribute set equal to the ID of the checkbox. - The modal comprises of a
modal-container
to wrap the modal content, amodal-header
for the title & close button, themodal-body
for the main content & themodal-footer
for action buttons. - The
modal-overlay
is 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>