Dropdown
A plain dropdown menu - zero JavaScript, closes automatically
when clicked outside its area. Two variants: the classic one
built on <details> (navbar), and a popover
in the top layer (anywhere the container clips its content -
tables, cards, modals).
Basic Dropdown
<details class="dropdown"> +
<summary class="dropdown-toggle"> as the
trigger, .dropdown-menu with
.dropdown-item links as the content.
Options
Actions
<details class="dropdown">
<summary class="dropdown-toggle btn btn-outline-dark">
Options
</summary>
<div class="dropdown-menu">
<a href="#" class="dropdown-item">Edit</a>
<a href="#" class="dropdown-item">Duplicate</a>
<a href="#" class="dropdown-item">Archive</a>
</div>
</details>
Dropdown as a popover (top layer)
The recommended variant outside the navbar: add
popovertarget="ID" to any existing
button and the popover attribute plus the
same id to .dropdown-menu. The menu
renders in the top layer (not clipped by
overflow - e.g. inside a
.table-wrapper or a modal) and anchors itself to
its button automatically - no .dropdown wrapper
needed.
<!-- Any existing button + popovertarget -->
<button class="btn btn-outline-dark" popovertarget="pop-menu">Options ▾</button>
<!-- [popover] = top layer: the menu isn't clipped by overflow -->
<div class="dropdown-menu" popover id="pop-menu">
<a href="#" class="dropdown-item">Edit</a>
<a href="#" class="dropdown-item">Duplicate</a>
<a href="#" class="dropdown-item">Archive</a>
</div>
<!-- Align to the right edge of the button -->
<div class="dropdown-menu dropdown-menu-end" popover id="pop-menu-2">...</div>