CSS Dropdown
Also see /react/dropdown
React component
Topbar dropdown
Using the browser-native Popover Web
API, we don't
have to worry about click/touch/keypress event handlers, or z-index
.
The .bf-dropdown
class only styles the popover container, and does not help
with positioning.
Unfortunately, CSS Anchor Positioning is not supported by Firefox or Safari
yet, but for dropdowns in topbar
it's probably sufficient to place it manually with top
and right
.
<style> .topbar-popover { top: calc(var(--bf-nav-top-height) + 8px); right: 8px; /* or whatever makes sense for your case */ } </style> <!-- demo button, yours would be placed inside .bf-nav-top-content (see Nav docs or sandbox below) --> <button popovertarget="topbardropdown" class="bf-button">Toggle popover</button> <!-- popovers can technically be placed anywhere in the DOM. A sibling to the <button> is not a bad idea. --> <div popover id="topbardropdown" class="bf-dropdown topbar-popover"> Hello, world! </div>
<style> .topbar-popover { top: calc(var(--bf-nav-top-height) + 8px); right: 8px; /* or whatever makes sense for your case */ } </style> <!-- demo button, yours would be placed inside .bf-nav-top-content (see Nav docs or sandbox below) --> <button popovertarget="topbardropdown" class="bf-button">Toggle popover</button> <!-- popovers can technically be placed anywhere in the DOM. A sibling to the <button> is not a bad idea. --> <div popover id="topbardropdown" class="bf-dropdown topbar-popover"> Hello, world! </div>
For anchored positioning you can use a JS library like https://floating-ui.com/ until CSS anchor positioning is better supported.
Color mode picker
Also see /css/radio
Radio buttons
<style> .color-mode-picker { top: calc(var(--bf-nav-top-height) + 8px); right: 8px; } </style> <button popovertarget="colormodedropdown" class="bf-button"> Toggle color mode picker </button> <div popover id="colormodedropdown" class="bf-dropdown color-mode-picker"> <div class="bf-nav-group-dropout-content"> <section> <div class="bf-nav-header">Color mode</div> <form id="colormodeform"> <label class="bf-checkbox"> <input type="radio" name="colormode" value="light" /> <span class="bf-checkbox-icon"> <i class="bf-checkbox-checked fa-solid fa-circle-dot"></i> <i class="bf-checkbox-unchecked fa-regular fa-circle"></i> </span> Light </label> <label class="bf-checkbox"> <input type="radio" name="colormode" value="dark" /> <span class="bf-checkbox-icon"> <i class="bf-checkbox-checked fa-solid fa-circle-dot"></i> <i class="bf-checkbox-unchecked fa-regular fa-circle"></i> </span> Dark </label> <label class="bf-checkbox"> <input type="radio" name="colormode" value="system" checked /> <span class="bf-checkbox-icon"> <i class="bf-checkbox-checked fa-solid fa-circle-dot"></i> <i class="bf-checkbox-unchecked fa-regular fa-circle"></i> </span> System </label> </form> </section> </div> </div>
<style> .color-mode-picker { top: calc(var(--bf-nav-top-height) + 8px); right: 8px; } </style> <button popovertarget="colormodedropdown" class="bf-button"> Toggle color mode picker </button> <div popover id="colormodedropdown" class="bf-dropdown color-mode-picker"> <div class="bf-nav-group-dropout-content"> <section> <div class="bf-nav-header">Color mode</div> <form id="colormodeform"> <label class="bf-checkbox"> <input type="radio" name="colormode" value="light" /> <span class="bf-checkbox-icon"> <i class="bf-checkbox-checked fa-solid fa-circle-dot"></i> <i class="bf-checkbox-unchecked fa-regular fa-circle"></i> </span> Light </label> <label class="bf-checkbox"> <input type="radio" name="colormode" value="dark" /> <span class="bf-checkbox-icon"> <i class="bf-checkbox-checked fa-solid fa-circle-dot"></i> <i class="bf-checkbox-unchecked fa-regular fa-circle"></i> </span> Dark </label> <label class="bf-checkbox"> <input type="radio" name="colormode" value="system" checked /> <span class="bf-checkbox-icon"> <i class="bf-checkbox-checked fa-solid fa-circle-dot"></i> <i class="bf-checkbox-unchecked fa-regular fa-circle"></i> </span> System </label> </form> </section> </div> </div>
Sandbox
Also see /css/nav
Build a fully responsive navigation menu