menu.css

A CSS framework for custom 'nav'

Description

This page shows how a page looks like if this code is added to the <head>:

<link
    rel="stylesheet"
    href="https://sourceforge.net/p/whakerexa/code/ci/master/tree/statics/css/wexa.css?format=raw"
    media="all" />
<link
    rel="stylesheet"
    href="https://sourceforge.net/p/whakerexa/code/ci/master/tree/statics/css/menu.css?format=raw"/>
            

Overview

menu.css/js is an extension of the wexa.css framework dedicated to navigation menus. It provides both the styling and the interactive behavior to create accessible and responsive navigation bars.

With menu.css you can design menus at the top, bottom or left-side of the page, including collapsible and pinnable side menus. The companion menu.js adds the necessary JavaScript to manage interactivity such as opening and closing submenus, pinning/unpinning the side menu, and maintaining keyboard accessibility.

The framework is designed to be lightweight, accessible by default, and to require a minimum of additional HTML classes, keeping source code clear and readable.

Not convinced? Take a look at the source code of this page!

Usage

By default, menu.css creates a horizontal navigation bar that is sticky at the top of the page. This is the most common layout, suitable for desktop websites. This solution is not responsive.

Other layouts are available:

Each layout reuses the same HTML structure, but applies different CSS rules depending on the class of the <nav> element (top, bottom, or side). Customization is achieved with the variables defined above, so developers can easily adapt height, width, or expanded/collapsed behavior.

The companion menu.js ensures interactivity: it manages toggle buttons, pin/unpin actions for side menus, submenu open/close states, and ARIA attributes for accessibility. Keyboard navigation (Tab, Shift+Tab, Escape) is fully supported by default.

The class .focus-visible-only defines a visual behavior for interactive elements that stay hidden until they receive keyboard focus. It can be applied to skip links or other accessibility controls to ensure they become visible only when navigated by keyboard.

Menu buttons

The navigation framework defines three dedicated buttons, each one designed for a specific type of menu and screen size:

The variables

Menus can be fully customized through CSS variables. These variables allow you to adapt the size, width, or alignment of menu items without modifying the CSS code directly. They make it easy to create consistent designs across different types of menus (top, bottom, side) while keeping flexibility for application-specific needs.

Variable Default value Description
--nav-min-height max(calc(6rem / var(--size-divisor)), 4rem); Minimum height of the main nav bar (top/bottom).
--nav-min-width 0 Minimum width of the nav (set >0 for side menus).
--nav-item-min-height max(calc(2rem / var(--size-divisor)), 2rem) Minimum height of any menu item.
--nav-item-height max(calc(2.5rem / var(--size-divisor)), 2.5rem) Default height of any menu item.
--nav-item-max-height max(calc(3rem / var(--size-divisor)), 3rem) Maximum height of any menu item.
--nav-item-min-width-h max(calc(6rem / var(--size-divisor)), 4rem) Min width of horizontal items (top/bottom).
--nav-item-width-h max(calc(8rem / var(--size-divisor)), 6rem) Default width of horizontal items.
--nav-item-max-width-h max(calc(15rem / var(--size-divisor)), 12rem) Max width of horizontal items.
--nav-expanded-width max(calc(16rem / var(--size-divisor)), 14rem); Width of the side menu when expanded/pinned.
--nav-item-width-v-collapsed var(--nav-min-width) Item width in side menu (collapsed).
--nav-item-width-v-expanded var(--nav-expanded-width) Item width in side menu (expanded).
--appmenu-position left Default off-canvas edge for app submenus (left/right/top/bottom).
--appmenu-align left bottom Submenu inner alignment (horizontal vertical).
--menu-button-size max(calc(4rem / var(--size-divisor)), 3rem) Size of the hamburger menu button