跳到主要内容

Navs and tabs

Documentation and examples for how to use Bootstrap’s included navigation components.

Base Nav

Navigation bits in Bootstrap all share a general Nav component and styles. Swap variants to switch between each style. The base Nav component is built with flexbox and provide a strong foundation for building all types of navigation components.

结果
Loading...
实时编辑器

<Nav> markup is very flexible and styling is controlled via classes so you can use whatever elements you like to build your navs. By default <Nav> and <Nav.Item> both render <div>s instead of <ul> and <li> elements respectively. This because it's possible (and common) to leave off the <Nav.Item>'s and render a <Nav.Link> directly, which would create invalid markup by default (ul > a).

When a <ul> is appropriate you can render one via the as prop; be sure to also set your items to <li> as well!

结果
Loading...
实时编辑器

Available styles

You can control the the direction and orientation of the Nav by making use of the flexbox utility classes. By default, navs are left-aligned, but that is easily changed to center or right-aligned.

结果
Loading...
实时编辑器

Vertical

Create stacked navs by changing the flex item direction with the .flex-column class, or your own css. You can even use the responsive versions to stack in some viewports but not others (e.g. .flex-sm-column).

结果
Loading...
实时编辑器

Tabs

Visually represent nav items as "tabs". This style pairs nicely with tabbable regions created by our Tab components.

Note: creating a vertical nav (.flex-column) with tabs styling is unsupported by Bootstrap's default stylesheet.

结果
Loading...
实时编辑器

Pills

结果
Loading...
实时编辑器

Underline

结果
Loading...
实时编辑器

Fill and justify

Force the contents of your nav to extend the full available width. To proportionately fill the space use fill. Notice that the nav is the entire width but each nav item is a different size.

结果
Loading...
实时编辑器

If you want each NavItem to be the same size use justify.

结果
Loading...
实时编辑器

Using dropdowns

You can mix and match the Dropdown components with the NavLink and NavItem components to create a Dropdown that plays well in a Nav component

结果
Loading...
实时编辑器

The above demonstrates how flexible the component model can be. But if you didn't want to roll your own versions we've included a straight-forward <NavDropdown> that works for most cases.

结果
Loading...
实时编辑器

API