Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap Navbar

Bootstrap Navbar

The navbar is a great feature and a prominent characteristic of Bootstrap websites. The navbar serves as a responsive foundation component for the navigation header in your application or website. The navbar is collapsed in the view of mobile devices, and expands horizontally as the available viewport width increases. At the core of the Bootstrap navbar, it includes the site name and basic navigation definition styles.

Default Navbar

The steps to create a default navbar are as follows:

The following example demonstrates this:

Example

<nav class=">

navbar navbar-default

"

role

=

"

navigation

"

<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="">

Runoob Tutorial

a

div

<div>
<ul class=">

nav navbar-nav

"

<li class="active">
<a href="" iOS a li>
<li>
<a href="" SVN a li>
<li class="dropdown">
<a href="" class="dropdown-toggle" data-toggle="dropdown" Java>
<b class="caret" b a>
<ul class="dropdown-menu">
<li>
<a href="" jmeter a li>
<li>
<a href="" EJB a li>
<li>
<a href="">

Jasper Report

a

li

<li class="divider" li>
<li>
<a href="">

Separated link

a

li

<li class="divider" li>
<li>
<a href="">

Another separate link

a

li

ul

li

ul

div

div

nav

Try it »

The result is as follows:


Responsive Navbar

To add responsive features to the navbar, the content you want to collapse must be wrapped in a div with class .collapse、.navbar-collapse 's

. The collapsed navbar is actually a button with class .navbar-toggle and two data- elements. The first is data-toggle, which tells JavaScript what to do with the button; the second is data-target, indicating which element to toggle. Three elements with class .icon-bar 's create the so-called hamburger button. These toggle the .nav-collapse
elements. To achieve all the above features, you must include Bootstrap Collapse Plugin。

The following example demonstrates this:

Example

<nav class=">

navbar navbar-default

"

role

=

"

navigation

"

<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse">
<span class="sr-only">

Toggle Navigation

span

<span class="icon-bar" span>
<span class="icon-bar" span>
<span class="icon-bar" span button>
<a class="navbar-brand" href="">

Runoob Tutorial

a

div

<div class=">

collapse navbar-collapse

"

id

=

"

example-navbar-collapse

"

<ul class=">

nav navbar-nav

"

<li class="active">
<a href="" iOS a li>
<li>
<a href="" SVN a li>
<li class="dropdown">
<a href="" class="dropdown-toggle" data-toggle="dropdown" Java>
<b class="caret" b a>
<ul class="dropdown-menu">
<li>
<a href="" jmeter a li>
<li>
<a href="" EJB a li>
<li>
<a href="">

Jasper Report

a

li

<li class="divider" li>
<li>
<a href="">

Separated link

a

li

<li class="divider" li>
<li>
<a href="">

Another separate link

a

li

ul

li

ul

div

div

nav

Try it »

The result is as follows:

Forms in the Navbar

Forms in the navbar do not use the Bootstrap Forms default class discussed in the chapter; instead, they use the .navbar-form class. This ensures proper vertical alignment of the form and collapsing behavior in narrower viewports. Use the alignment options (which will be explained in detail in the component alignment section) to decide where to place content in the navbar.

The following example demonstrates this:

Example

<nav class=">

navbar navbar-default

"

role

=

"

navigation

"

<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="">

Runoob Tutorial

a

div

<form class=">

navbar-form navbar-left

"

role

=

"

search

"

<div class="form-group">
<input type="text" class="form-control" placeholder="Search" div>
<button type="submit" class=">

btn btn-default

"

Submit

button

form

div

nav

Try it »

The result is as follows:

Buttons in the Navbar

You can use the class .navbar-btn Add buttons to elements that are not in a

The