A dark navigation bar with a nested multi-level dropdown: the top menu opens below the bar and each submenu flies out to the side, three levels deep. It is written in plain CSS with a small vanilla JavaScript file for hover, click, touch and keyboard control, and suits product catalogs, documentation sites and SaaS headers with deep information architecture.
How it works
The root div.mld-site holds nav.mld-nav (brand link and ul.mld-bar) and a .mld-stage demo area that gives the open menus room in the preview. Every item is an li.mld-item. Items with children get .mld-has-sub and contain a button.mld-toggle followed directly by a ul.mld-menu; deeper menus also carry .mld-menu--sub. Top-level controls use .mld-top, menu entries use .mld-link.
Visibility is driven by ARIA state alone: .mld-toggle[aria-expanded="true"] + .mld-menu is shown, every other menu stays at display: none. From 720px the first menu is positioned under its button and each .mld-menu--sub sits at left: calc(100% + 0.4375rem) next to its parent, with invisible ::before bridges so the pointer can cross the gap. Below 720px the first menu becomes a full-width panel and deeper levels expand inline as an indented accordion with an accent border.
The script initializes every .mld-nav. It toggles aria-expanded on click, opens branches on mouseenter and closes them HOVER_CLOSE_DELAY milliseconds after mouseleave (mouse users on wide screens only), keeps one open branch per level and closes all nested branches with their parent. When a flyout would leave the viewport, place() adds .mld-menu--left so it opens to the left instead. Clicks outside and focus leaving the nav close everything. The demo starts with Products, Software and Integrations open via aria-expanded="true" in the markup; set them to false for a closed start.
Customization
--mld-accenton.mld-site: logo, chevrons, focus rings and the inline border on mobile.--mld-barand--mld-menu-bg: background of the bar and of every menu panel.--mld-menu-width: width of each dropdown and flyout on wide screens.--mld-hover: background of hovered and expanded menu entries.HOVER_CLOSE_DELAYinscript.js: raise it to make flyouts more forgiving for diagonal mouse movement.- The
720pxbreakpoint instyle.cssand in thedesktopmedia query inscript.js: change both together to switch to flyouts earlier or later. - Remove
.mld-stageand themin-heighton.mld-sitewhen you place the nav in a real header.
Use cases
- Large websites: a three-level dropdown organizes many pages in one dark navigation bar
- Desktop menus: flyout submenus open on hover or click beside the parent menu item
- Mobile navigation: nested items become an inline accordion on small screens
- Accessible sites: full keyboard support lets visitors open and close every level
Accessibility
The menu follows the disclosure navigation pattern: real button elements with aria-expanded and aria-controls, real links, and a nav landmark labelled "Main". Tab reaches every control. Arrow Down opens a top menu and focuses its first entry, Arrow Up/Down move inside a menu, Arrow Right opens a submenu, Arrow Left and Escape close the current level and return focus to its button, and Home/End jump to the first or last entry. All controls have a visible :focus-visible outline, and animations are removed with prefers-reduced-motion: reduce.
Usage notes
Every aria-controls value must match a unique id; prefix them when you place two navs on one page.