Bootstrap Navbar
Introduction
With Bootstrap, you can create a static navbar. This tutorial will teach you how to do that.
We will use an HTML5 page with content and see how to add a header navbar. Here is the final output:

Here is the HTML5 code of the page without any content.
Bootstrap基本的基于与标签的导航
To create the basic structure containing navigation, you need to insert the following code in the HTML5 code shown above, immediately after the tag:
Now, let's replace with the following code to create the first set of navigation. Note that the "brand" class here is rendered differently; it can be used to display your company name or organization name.
If you need to create a dropdown menu, insert the following code immediately after the HTML code shown in the last code block.
However, since Bootstrap dropdown menus require JavaScript, you need to insert the following two lines of code into your HTML page. You can insert them before the tag.
If you want to insert a search form into the navbar, simply add it right after the element containing the dropdown menu list in the
-
markup by inserting the following code. Note that the class "pull-left" left-aligns the search form. If you want it right-aligned, use the "pull-right" class.
Now we want to insert social buttons into the navbar, on the right side. We will insert the Google Plus, Facebook Like, and Tweet buttons. You need to insert the following code after the search form.
The class "socials" is not part of bootstrap.css. Since we want all the social buttons to be center-aligned, we use it to create some padding. The code is as follows:
.socials {
padding: 10px;
}
You can write it directly on the page, enclosed in a tag, or add it to an external CSS file and then reference it.
Finally, you need to insert two pieces of code. One is for the Facebook button and the other for Google Plus. These are provided by Facebook and Google to dynamically insert buttons into your page.
So, right after the opening body tag, insert the following code, which is for Facebook
Then, right before the closing body tag, insert the following code, which is for Google Plus
Here is the final code
Example
.socials {
padding: 10px;
}
Click here to view the example online.
Note that you need to add 40px of padding after the opening body tag. Add it after the core Bootstrap CSS and before the optional responsive CSS.
Bootstrap also allows you to create a responsive navbar. Here is the code:
Example
Click here to download all the HTML, CSS, JS, and image files used in this tutorial.