

Photo: Nicole Geri
Collapse
Introduction
Toggle the visibility of a block-level selector from a button located anywhere in the DOM.
The Collapse Relationship
The collapse mechanism establishes a relationship between a button and its target selector. With each button press, the target’s visibility toggles between show and hide.
<button class="button width-100 theme-primary" data-toggle="collapse" aria-controls="target-id" aria-expanded="false" type="button"> Navigation</button>
<div class="collapse margin-y-3" id="target-id"> <div class="border padding-3"> <nav aria-label="Example navigation"> <ul class="nav nav--divider"> <li> <a href="#1">Link</a> </li> <li> <a href="#1">Link</a> </li> <li> <a href="#1">Link</a> </li> </ul> </nav> </div></div>| Lines | Details |
|---|---|
| 3-6 | On a The The |
| 11-27 | The |
Close Target
To close a selector while opening another, add the data-target-close attribute to a button. The value should equal the target selector’s id attribute.
In Figure 2, each button’s data-target-close value matches the other button’s target panel id, so opening one panel closes the neighboring panel.
Target 1
Target 2
<div class="grid grid--column-2 gap-3"> <button class="button width-100 theme-primary" data-toggle="collapse" aria-controls="target-id-1" aria-expanded="false" data-target-close="target-id-2" type="button" > Button 1 </button>
<button class="button width-100 theme-primary" data-toggle="collapse" aria-controls="target-id-2" aria-expanded="false" data-target-close="target-id-1" type="button" > Button 2 </button></div>
<div class="collapse margin-y-3" id="target-id-1"> <div class="border padding-4"> <p>Target 1</p> </div></div>
<div class="collapse margin-y-3" id="target-id-2"> <div class="border padding-4"> <p>Target 2</p> </div></div>













































