To start, navbars are static (not fixed to the top) and include support for a project name and basic navigation. Place one anywhere within a .container
, which sets the width of your site and content.
- <div class=«navbar»>
- <div class=«navbar-inner»>
- <a class=«brand» href=«#»>Title</a>
- <ul class=«nav»>
- <li class=«active»><a href=«#»>Home</a></li>
- <li><a href=«#»>Link</a></li>
- <li><a href=«#»>Link</a></li>
- </ul>
- </div>
- </div>
Navbar components
Brand
A simple link to show your brand or project name only requires an anchor tag.
- <a class=«brand» href=«#»>Project name</a>
Nav links
Nav items are simple to add via unordered lists.
- <ul class=«nav»>
- <li class=«active»>
- <a href=«#»>Home</a>
- </li>
- <li><a href=«#»>Link</a></li>
- <li><a href=«#»>Link</a></li>
- </ul>
You can easily add dividers to your nav links with an empty list item and a simple class. Just add this between links:
- <ul class=«nav»>
- …
- <li class=«divider-vertical»></li>
- …
- </ul>
Forms
To properly style and position a form within the navbar, add the appropriate classes as shown below. For a default form, include .navbar-form
and either .pull-left
or .pull-right
to properly align it.
- <form class=«navbar-form pull-left»>
- <input type=«text» class=«span2»>
- <button type=«submit» class=«btn»>Submit</button>
- </form>
Search form
For a more customized search form, add .navbar-search
to the form
and .search-query
to the input for specialized styles in the navbar.
- <form class=«navbar-search pull-left»>
- <input type=«text» class=«search-query» placeholder=«Search»>
- </form>
Component alignment
Align nav links, search form, or text, use the .pull-left
or .pull-right
utility classes. Both classes will add a CSS float in the specified direction.
Using dropdowns
Add dropdowns and dropups to the nav with a bit of markup and the dropdowns javascript plugin.
- <ul class=«nav»>
- <li class=«dropdown»>
- <a href=«#» class=«dropdown-toggle» data-toggle=«dropdown»>
- Account
- <b class=«caret»></b>
- </a>
- <ul class=«dropdown-menu»>
- …
- </ul>
- </li>
- </ul>
Visit the javascript dropdowns documentation for more markup and information on calling dropdowns.
Text
Wrap strings of text in an element with .navbar-text
, usually on a <p>
tag for proper leading and color.
Optional display variations
Fix the navbar to the top or bottom of the viewport with an additional class on the outermost div, .navbar
.
Fixed to top
Add .navbar-fixed-top
and remember to account for the hidden area underneath it by adding at least 40px padding
to the <body>
. Be sure to add this after the core Bootstrap CSS and before the optional responsive CSS.
- <div class=«navbar navbar-fixed-top»>
- …
- </div>
Fixed to bottom
Add .navbar-fixed-bottom
instead.
- <div class=«navbar navbar-fixed-bottom»>
- …
- </div>
Static top navbar
Create a full-width navbar that scrolls away with the page by adding .navbar-static-top
. Unlike the .navbar-fixed-top
class, you do not need to change any padding on the body
.
- <div class=«navbar navbar-static-top»>
- …
- </div>
Responsive navbar
To implement a collapsing responsive navbar, wrap your navbar content in a containing div, .nav-collapse.collapse
, and add the navbar toggle button, .btn-navbar
.
- <div class=«navbar»>
- <div class=«navbar-inner»>
- <div class=«container»>
- <!– .btn-navbar is used as the toggle for collapsed navbar content –>
- <a class=«btn btn-navbar» data-toggle=«collapse» data-target=«.nav-collapse»>
- <span class=«icon-bar»></span>
- <span class=«icon-bar»></span>
- <span class=«icon-bar»></span>
- </a>
- <!– Be sure to leave the brand out there if you want it shown –>
- <a class=«brand» href=«#»>Project name</a>
- <!– Everything you want hidden at 940px or less, place within here –>
- <div class=«nav-collapse»>
- <!– .nav, .navbar-search, .navbar-form, etc –>
- </div>
- </div>
- </div>
- </div>
Inverted variation
Modify the look of the navbar by adding .navbar-inverse
.
- <div class=«navbar navbar-inverse»>
- …
- </div>