03/Structure
Mobile menu
Full-screen menu that slides in from the right below the navbar. It closes when a link is chosen, with Esc, or when switching to desktop.
Button and panel
The button points to the panel's id with data-cb-mobile-toggle. Shrink the window below 960px to see it work.
HTML
<button class="cb-icon-btn" type="button" data-cb-mobile-toggle="demo-mobile" aria-label="Menú">
<svg class="cb-burger__open" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
<svg class="cb-burger__close" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg>
</button>
<nav class="cb-mobile-menu" id="demo-mobile" data-cb-mobile-menu aria-label="Menú móvil">
<a class="cb-mobile-menu__link" href="#">Inicio <span class="cb-mobile-menu__meta">01</span></a>
<a class="cb-mobile-menu__link" href="#">Servicios <span class="cb-mobile-menu__meta">02</span></a>
<div class="cb-label cb-mobile-menu__label"><b>//</b>Productos</div>
<a class="cb-mobile-menu__link" href="#">Facturación <span class="cb-mobile-menu__meta">↗</span></a>
<a href="#" class="cb-btn cb-btn--primary cb-mobile-menu__cta">Empezar ↗</a>
</nav>
Classes and modifiers
| Class | Description |
|---|---|
.cb-mobile-menu | Fixed panel below the navbar. .is-open shows it. |
.cb-mobile-menu__link | Large link with a bottom border. |
.cb-mobile-menu__meta | Number or arrow on the right of the link. |
.cb-mobile-menu__label | Section separator (combined with .cb-label). |
.cb-mobile-menu__cta | Full-width button at the end. |
.cb-burger__open, .cb-burger__close | Icons that swap depending on aria-expanded. |
data-cb-* attributes
| Attribute | Description |
|---|---|
data-cb-mobile-menu | Marks the panel. Needs an id. |
data-cb-mobile-toggle="id" | Button that opens and closes the panel. |
JavaScript
| Event | When it fires |
|---|---|
cb:open / cb:close | On the panel. cb:open can be canceled. |
Accessibility
- The button automatically gets
aria-expandedandaria-controls. - When closed it has
visibility: hidden, so its links don't receive focus. - Esc closes the menu and returns focus to the button.