Skip to content
npm ↗ GitHub ↗

Documentation

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

ClassDescription
.cb-mobile-menuFixed panel below the navbar. .is-open shows it.
.cb-mobile-menu__linkLarge link with a bottom border.
.cb-mobile-menu__metaNumber or arrow on the right of the link.
.cb-mobile-menu__labelSection separator (combined with .cb-label).
.cb-mobile-menu__ctaFull-width button at the end.
.cb-burger__open, .cb-burger__closeIcons that swap depending on aria-expanded.

data-cb-* attributes

AttributeDescription
data-cb-mobile-menuMarks the panel. Needs an id.
data-cb-mobile-toggle="id"Button that opens and closes the panel.

JavaScript

EventWhen it fires
cb:open / cb:closeOn the panel. cb:open can be canceled.

Accessibility

  • The button automatically gets aria-expanded and aria-controls.
  • When closed it has visibility: hidden, so its links don't receive focus.
  • Esc closes the menu and returns focus to the button.