Getting Started With Bootstrap: Part 3

I have started an article series. The first part, Getting Started with Bootstrap, provided a basic introduction to Bootstrap and Bootstrap layout.

In this article, we'll learn:

  • Twitter Bootstrap Nav
  • Twitter Bootstrap Navbar
  • Twitter Bootstrap Panels
  • Twitter Bootstrap Breadcrumbs
  • Twitter Bootstrap Pagination
  • Twitter Bootstrap Pager
  • Twitter Bootstrap Progress Bars

Twitter Bootstrap Nav

This section explains how to create Twitter Bootstrap nav components. You can easily create nav components such as tabs and pills using Twitter Bootstrap. Bootstrap's nav components (tabs and pills) share the same base markup and styles through the .nav class.

Creating Basic Tabs Nav

You can use .nav-tabs class with the base class .nav. The following example will show you how to create a basic tab component using Bootstrap.

HTML Code

  1. <ul class="nav nav-tabs">  
  2.   <li class="active"><a href="#">Home</a></li>  
  3.   <li><a href="#">Technologies</a></li>  
  4.   <li><a href="#">Blog</a></li>  
  5. </ul>  
Result



Creating Basic Pills Nav

Similarly you can use the .nav-pills class with base class .nav without any further change in markup.

HTML Code
  1. <ul class="nav nav-pills">  
  2.   <li class="active"><a href="#">Home</a></li>  
  3.   <li><a href="#">Technologies</a></li>  
  4.   <li><a href="#">Blog</a></li>  
  5. </ul>  
Result


Stacked Pills Nav

Pills navigations are horizontal by default. If you want to make vertical stacked pills navigation you just add an extra class .nav-stacked.

HTML Code
  1. <ul class="nav nav-pills nav-stacked">  
  2.   <li class="active"><a href="#">Home</a></li>  
  3.   <li><a href="#">Technologies</a></li>  
  4.   <li><a href="#">Blog</a></li>  
  5. </ul>  
Result


Creating the Dropdown with Twitter Bootstrap Tabs and Pills

You can add dropdown menus to a link inside tabs and pills navigation with a little extra markup and including JavaScript library files jquery.js and bootstrap.js in your HTML file.

HTML Code
  1. <ul class="nav nav-tabs">  
  2.   <li class="active"><a href="#">Home</a></li>  
  3.   <li><a href="#">Article</a></li>  
  4.   <li class="dropdown"> <a href="#" data-toggle="dropdown" class="dropdown-toggle">Technologies <b class="caret"></b></a>  
  5.     <ul class="dropdown-menu">  
  6.       <li><a href="#">Java</a></li>  
  7.       <li><a href="#">C++</a></li>  
  8.       <li><a href="#">Asp.Net</a></li>  
  9.       <li class="divider"></li>  
  10.       <li><a href="#">HTML</a></li>  
  11.     </ul>  
  12.   </li>  
  13. </ul>  
Result



To create the Pills with Dropdowns you will changed the .nav-tabs to .nav-pills.

HTML Code
  1. <ul class="nav nav-pills">  
  2.   <li class="active"><a href="#">Home</a></li>  
  3.   <li><a href="#">Article</a></li>  
  4.   <li class="dropdown"> <a href="#" data-toggle="dropdown" class="dropdown-toggle">Technologies <b class="caret"></b></a>  
  5.     <ul class="dropdown-menu">  
  6.       <li><a href="#">Java</a></li>  
  7.       <li><a href="#">C++</a></li>  
  8.       <li><a href="#">Asp.Net</a></li>  
  9.       <li class="divider"></li>  
  10.       <li><a href="#">HTML</a></li>  
  11.     </ul>  
  12.   </li>  
  13. </ul>  
Result



Justified Tabs and Pills

You can easily make your tabs and pills nav having width equal to their parent element by simply adding an extra class .nav-justified. It works only on screens that are wider than 768px, other than the nav links are stacked.

HTML Code

  1. <!-- justified tabs -->  
  2. <h5> Justified Tabs </h5>  
  3. <ul class="nav nav-tabs nav-justified">  
  4.   <li class="active"><a href="#">Home</a></li>  
  5.   <li><a href="#">Technologies</a></li>  
  6.   <li><a href="#">Blog</a></li>  
  7. </ul>  
  8.   
  9. <!-- justified pills -->   
  10. <h5> Justified Pills </h5>  
  11. <ul class="nav nav-pills nav-justified">  
  12.   <li class="active"><a href="#">Home</a></li>  
  13.   <li><a href="#">Technologies</a></li>  
  14.   <li><a href="#">Blog</a></li>  
  15. </ul>  
Result



Twitter Bootstrap Navbar

This section explains how to create static and fixed navbar components with Twitter Bootstrap.

Creating A Simple Navbar with Twitter Bootstrap

You can create various variations of navbars quickly and without too much effort. The procedure is listed below: 
  • Create nav container with class .navigation and .navbar-default.
  • For better mobile display you need to create a container with the class .navbar-header. Inside this container, you can create a button to toggle the menu items using data-target.
  • Now, you can create your menu item list container. This container has the same id as data-target and the class is .collapse and .navbar-collapse.
  • Create menu list with ul li structure with the class .nav and .navbar-nav

The following example will you show how to create a static navbar with basic navigation.

HTML Code

  1. <nav role="navigation" class="navbar navbar-default">   
  2.   <!-- Brand and toggle get grouped for better mobile display -->  
  3.   <div class="navbar-header">  
  4.     <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>  
  5.     <a href="#" class="navbar-brand">C# Corner</a> </div>  
  6.   <!-- Collection of nav links and other content for toggling -->  
  7.   <div id="navbarCollapse" class="collapse navbar-collapse">  
  8.     <ul class="nav navbar-nav">  
  9.       <li class="active"><a href="#">Home</a></li>  
  10.       <li><a href="#">Article</a></li>  
  11.       <li><a href="#">Technologies</a></li>  
  12.     </ul>  
  13.     <ul class="nav navbar-nav navbar-right">  
  14.       <li><a href="#">Login</a></li>  
  15.     </ul>  
  16.   </div>  
  17. </nav>       
Result



Mobile Display



Creating Fixed Navbar with Twitter Bootstrap

Twitter Bootstrap also provides a mechanism to create a navbar that is fixed on the top or bottom of the viewport and will scroll with the content on the page. Add an extra class .navbar-fixed-top or .navbar-fixed-bottom in addition to the .navbar and .navbar-default base class to create navbars that are fixed on the top or bottom.

HTML Code

  1. <nav role="navigation" class="navbar navbar-default navbar-fixed-bottom">   
  2.   <!-- Brand and toggle get grouped for better mobile display -->  
  3.   <div class="navbar-header">  
  4.     <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>  
  5.     <a href="#" class="navbar-brand">C# Corner</a> </div>  
  6.   <!-- Collection of nav links and other content for toggling -->  
  7.   <div id="navbarCollapse" class="collapse navbar-collapse">  
  8.     <ul class="nav navbar-nav">  
  9.       <li class="active"><a href="#">Home</a></li>  
  10.       <li><a href="#">Article</a></li>  
  11.       <li><a href="#">Technologies</a></li>  
  12.     </ul>  
  13.     <ul class="nav navbar-nav navbar-right">  
  14.       <li><a href="#">Login</a></li>  
  15.     </ul>  
  16.   </div>  
  17. </nav>  
Result



Mobile Display



Note: You can fix .navbar content inside the .container or .container-fluid for proper padding and alignment with the rest of the content. Remember to add padding (at least 70px) to the top or bottom of the <body> element to avoid the content going underneath the navbar when implementing the fixed top or bottom navbar. Also be sure to add your custom style sheet after the core Bootstrap CSS file, otherwise it may not work.

Twitter Bootstrap Panels

This section explains how to create panels with Twitter bootstrap. Sometimes you might need to put your content in a box for a certain reason. In such a condition we can use panel components. In the most basic form the panel component applies a border and padding around the content. The following example will you show how to create simple panels.

HTML Code
  1. <div class="panel panel-default">  
  2.   <div class="panel-body">Look, I'm in a panel!</div>  
  3. </div>  
Result



You can also add a heading to your panel with the .panel-heading class.

HTML Code
  1. <div class="panel panel-default">  
  2.   <div class="panel-heading">Heading Page</div>  
  3.   <div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec bibendum, leo vel venenatis finibus, purus nisl varius arcu, vel pulvinar turpis sapien at sapien. </div>  
  4. </div>  
Result



Panels with Contextual States

In Twitter Bootstrap you can also add contextual classes like .panel-primary.panel-success.panel-info.panel-warning, or .panel-danger on the panel components to make it more meaningful and the drawing attention of the user.

HTML Code
  1. <div class="panel panel-primary">  
  2.   <div class="panel-heading">  
  3.     <h3 class="panel-title">Primary</h3>  
  4.   </div>  
  5.   <div class="panel-body">The requested page has been permanently moved to a new location.</div>  
  6. </div>  
  7. <div class="panel panel-success">  
  8.   <div class="panel-heading">  
  9.     <h3 class="panel-title">Success</h3>  
  10.   </div>  
  11.   <div class="panel-body">The server successfully processed the request.</div>  
  12. </div>  
  13. <div class="panel panel-info">  
  14.   <div class="panel-heading">  
  15.     <h3 class="panel-title">info</h3>  
  16.   </div>  
  17.   <div class="panel-body">The client should continue with its request.</div>  
  18. </div>  
  19. <div class="panel panel-warning">  
  20.   <div class="panel-heading">  
  21.     <h3 class="panel-title">Warning</h3>  
  22.   </div>  
  23.   <div class="panel-body">The request cannot be fulfilled due to bad syntax.</div>  
  24. </div>  
  25. <div class="panel panel-danger">  
  26.   <div class="panel-heading">  
  27.     <h3 class="panel-title">Danger</h3>  
  28.   </div>  
  29.   <div class="panel-body">The server is temporarily unable to handle the request.</div>  
  30. </div>  
Result



Twitter Bootstrap Breadcrumbs

This section explains how to create breadcrumbs with Twitter Bootstrap. A breadcrumb is a navigation scheme that indicates the user's location in a website or web application. The following example shows how to create breadcrumbs.

HTML Code

  1. <ul class="breadcrumb">  
  2.   <li><a href="#">Home</a></li>  
  3.   <li><a href="#">Products</a></li>  
  4.   <li class="active">Accessories</li>  
  5. </ul>  
Result


Twitter Bootstrap Pagination

This section explains how to create pagination with Twitter Bootstrap. Pagination is the process of organizing content by dividing it into separate pages. The following example show you how to create various types of pagination .
 
HTML Code
  1. <h3> Simple Pagination </h3>  
  2. <ul class="pagination">  
  3.   <li><a href="#">«</a></li>  
  4.   <li><a href="#">1</a></li>  
  5.   <li><a href="#">2</a></li>  
  6.   <li><a href="#">3</a></li>  
  7.   <li><a href="#">4</a></li>  
  8.   <li><a href="#">5</a></li>  
  9.   <li><a href="#">»</a></li>  
  10. </ul>  
  11. <h3> Pagination with Disabled and Active States </h3>  
  12. <ul class="pagination">  
  13.   <li class="disabled"><a href="#">«</a></li>  
  14.   <li class="active"><a href="#">1</a></li>  
  15.   <li><a href="#">2</a></li>  
  16.   <li><a href="#">3</a></li>  
  17.   <li><a href="#">4</a></li>  
  18.   <li><a href="#">5</a></li>  
  19.   <li><a href="#">»</a></li>  
  20. </ul>  
  21. <h3>Different Sizes of Pagination</h3>  
  22. <!-- Larger pagination -->  
  23. <ul class="pagination pagination-lg">  
  24.   <li><a href="#">«</a></li>  
  25.   <li><a href="#">1</a></li>  
  26.   <li><a href="#">2</a></li>  
  27.   <li><a href="#">3</a></li>  
  28.   <li><a href="#">4</a></li>  
  29.   <li><a href="#">5</a></li>  
  30.   <li><a href="#">»</a></li>  
  31. </ul>  
  32. <!-- Default pagination -->  
  33. <ul class="pagination">  
  34.   <li><a href="#">«</a></li>  
  35.   <li><a href="#">1</a></li>  
  36.   <li><a href="#">2</a></li>  
  37.   <li><a href="#">3</a></li>  
  38.   <li><a href="#">4</a></li>  
  39.   <li><a href="#">5</a></li>  
  40.   <li><a href="#">»</a></li>  
  41. </ul>  
  42. <!-- Smaller pagination -->  
  43. <ul class="pagination pagination-sm">  
  44.   <li><a href="#">«</a></li>  
  45.   <li><a href="#">1</a></li>  
  46.   <li><a href="#">2</a></li>  
  47.   <li><a href="#">3</a></li>  
  48.   <li><a href="#">4</a></li>  
  49.   <li><a href="#">5</a></li>  
  50.   <li><a href="#">»</a></li>  
  51. </ul>  
Result



Twitter Bootstrap Pager

In Bootstrap you can create a pager (Previous and Next links) on your website. For creating a pager with bootstrap you can add a bootstrap class .pager in the ul li structure.

HTML Code
  1. <ul class="pager">  
  2.   <li><a href="#">Previous</a></li>  
  3.   <li><a href="#">Next</a></li>  
  4. </ul>  
Result



Note: You can create an alignment of the pager using the .previous and .next class and you can disable the links using the .disable class.

Twitter Bootstrap Progress Bars

This section explains how to create progress bars using Twitter Bootstrap. Progress bars can be used for loading, redirecting, or showing action status to the users. To create Progress bars we can use the .progress class, it is a base class of the Twitter Bootstrap progress bar. We can create various types of progress by using different progress classes like .progress-striped , .progress-bar-success and so on with the base class .progress or .progress-bar. The following example will show how to create a simple progress bar with vertical gradient, Stripped and stacked.
HTML Code
  1. <h3> Vertical Gradient Progress Bar</h3>  
  2. <div class="progress">  
  3.   <div class="progress-bar" style="width: 60%;"> <span class="sr-only">60% Complete</span> </div>  
  4. </div>  
  5. <h3>Stripped Progress Bar</h3>  
  6. <div class="progress progress-striped">  
  7.   <div class="progress-bar" style="width: 60%;"> <span class="sr-only">60% Complete</span> </div>  
  8. </div>  
  9. <h3>Stacked Progress Bar</h3>  
  10. <div class="progress">  
  11.   <div class="progress-bar progress-bar-success" style="width: 35%"> <span class="sr-only">35% Complete (success)</span> </div>  
  12.   <div class="progress-bar progress-bar-warning" style="width: 20%"> <span class="sr-only">20% Complete (warning)</span> </div>  
  13.   <div class="progress-bar progress-bar-danger" style="width: 10%"> <span class="sr-only">10% Complete (danger)</span> </div>  
  14. </div>  
Result



Progress Bars with Emphasis Classes

Twitter Bootstrap also provides some emphasis utility classes for progress bars that can be used to convey meaning through color.

HTML Code

  1. <div class="progress">  
  2.   <div class="progress-bar progress-bar-info" style="width: 20%"> <span class="sr-only">80% Complete</span> </div>  
  3. </div>  
  4. <div class="progress">  
  5.   <div class="progress-bar progress-bar-success" style="width: 40%"> <span class="sr-only">60% Complete</span> </div>  
  6. </div>  
  7. <div class="progress">  
  8.   <div class="progress-bar progress-bar-warning" style="width: 60%"> <span class="sr-only">40% Complete</span> </div>  
  9. </div>  
  10. <div class="progress">  
  11.   <div class="progress-bar progress-bar-danger" style="width: 80%"> <span class="sr-only">20% Complete</span> </div>  
  12. </div>  
Result



Twitter Bootstrap utility components and classes

This section explains how to use Twitter Bootstrap utility components and classes. Twitter Bootstrap offers components and classes for better document structure: 
Classes Description
.jumbotron It's provides an excellent way to showcase the key content or information on a website like hero unit.
.well You can create simple inset effect to the element
.pull-left

Floats an element to left.

.pull-right

Floats an element to right.

.clearfix Clears the float on any element.

 

<<Go back to Part 2

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now