Navigation in dash-bootstrap-components is constructed using a hierarchy of components: Nav, NavItem, NavLink, and DropdownMenu.
To ensure consistent styling when using a DropdownMenu inside a Nav, you must set nav=True on the DropdownMenu component. This ensures it aligns correctly with NavItem and NavLink elements.
Layout Patterns:
- Standard: Wrap
NavLink inside NavItem inside a Nav. - Simplified: If you do not need layout features like
fill or justified, you can pass NavLink components directly as children of Nav without wrapping them in NavItem.
import dash_bootstrap_components as dbc
from dash import html
# Standard pattern
dbc.Nav([
dbc.NavItem(dbc.NavLink("Link 1", href="/")),
dbc.NavItem(dbc.NavLink("Link 2", href="/other")),
dbc.NavItem(dbc.DropdownMenu("Dropdown", nav=True, children=[...]))
])
# Simplified pattern (no NavItem wrapper needed if not using fill/justified)
dbc.Nav([
dbc.NavLink("Link 1", href="/"),
dbc.NavLink("Link 2", href="/other")
])