Bootstrap Nav Elements
In this chapter we will explain some options provided by Bootstrap for defining nav elements. They use the same markup and base class .nav. Bootstrap also provides a helper class for sharing markup and states. By changing the modifier class, you can switch between different styles.
Tabular Navigation or Tabs
Create a tabbed navigation menu:
- Start with an unordered list with class .nav .
- Add the class .nav-tabs。
The following example demonstrates this:
Example
<
p
Tabbed Navigation Menu
p
<ul class=">nav nav-tabs
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
Pill-style Navigation Menu
Basic Pill-style Navigation Menu
If you want to change tabs to pills, just use the class .nav-pills instead of .nav-tabs instead; the other steps are the same as above.
The following example demonstrates this:
Example
<
p
Basic Pill-style Navigation Menu
p
<ul class=">nav nav-pills
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
Vertical Pill-style Navigation Menu
You can use the class .nav、.nav-pills together with the class .nav-stackedto stack the pills vertically.
The following example demonstrates this:
Example
<
p
Vertical Pill-style Navigation Menu
p
<ul class=">nav nav-pills nav-stacked
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
Justified Navigation
When the screen width is greater than 768px, by using the .nav、.nav-tabs or .nav、.nav-pills together with the class .nav-justifiedclass respectively, you can make tabbed or pill navigation menus equal in width to their parent element. On smaller screens, the navigation links will stack.
The following example demonstrates this:
Example
<
p
Justified Nav Elements
p
<ul class=">nav nav-pills nav-justified
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>
<br>
<br>
<br>
<ul class=">nav nav-tabs nav-justified
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
Disabled link
For each .nav class; if the .disabled class is added, a grey link is created and the link's :hover state is disabled, as shown in the example below:
Example
<
p
Disabled Links in Nav Elements
p
<ul class=">nav nav-pills
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li class="disabled">
<a href="">iOS (Disabled Link)
a
li
<li>
<a href="" VB.Net a li>
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>
<br>
<br>
<ul class=">nav nav-tabs
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li class="disabled">
<a href="">VB.Net (Disabled Link)
a
li
<li>
<a href="" Java a li>
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
This class only changes the appearance, not its functionality. Here, you need to use custom JavaScript to disable the link.
Dropdown menu
Nav menus and dropdown menus use similar syntax. By default, the anchors of list items work together with some data attributes to trigger an unordered list with the .dropdown-menu class.
Tabs with Dropdown Menus
The steps to add a dropdown menu to a tab are as follows:
- Start with an unordered list with class .nav .
- Add the class .nav-tabs。
- Add an unordered list with .dropdown-menu class.
Example
<
p
Tabs with Dropdown Menus
p
<ul class=">nav nav-tabs
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="" Java>
<span class="caret" span a>
<ul class="dropdown-menu">
<li>
<a href="" Swing a li>
<li>
<a href="" jMeter a li>
<li>
<a href="" EJB a li>
<li class="divider" li>
<li>
<a href="">Separated link
a
li
ul
li
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
Pills with Dropdown Menus
The steps are the same as creating tabs with dropdown menus, except that you need to change the .nav-tabs class to .nav-pills, as shown in the example below:
Example
<
p
Pills with Dropdown Menus
p
<ul class=">nav nav-pills
"
<li class="active">
<a href="" Home a li>
<li>
<a href="" SVN a li>
<li>
<a href="" iOS a li>
<li>
<a href="" VB.Net a li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="" Java>
<span class="caret" span a>
<ul class="dropdown-menu">
<li>
<a href="" Swing a li>
<li>
<a href="" jMeter a li>
<li>
<a href="" EJB a li>
<li class="divider" li>
<li>
<a href="">Separated link
a
li
ul
li
<li>
<a href="" PHP a li ul>Try it »
The result is as follows:
More Nav Element Component Examples
Tabs and Pill Tabs
| class | Description | Example |
|---|---|---|
| .nav nav-tabs | Tabs | Try it |
| .nav nav-pills | Pill Tabs | Try it |
| .nav nav-pills nav-stacked | Pill tabs stacked vertically | Try it |
| .nav-justified | Justified tabs; on screens larger than 768px, the .nav-justified class makes it easy to give tabs or pills equal width. On small screens, navigation links are stacked. | Try it |
| .disabled | Disabled Tabs | Try it |
| Add Dropdown Menu to Tabs | Try it | |
| Pill Tabs with Dropdown Menus | Try it | |
| .tab-content | Used together with .tab-pane and data-toggle="tab" (data-toggle="pill"), sets the content corresponding to the tab to change as the tab is switched | Try it |
| .tab-pane | Used together with .tab-content and data-toggle="tab" (data-toggle="pill"), sets the content corresponding to the tab to change as the tab is switched | Try it |
This class only changes the