Bootstrap Tutorial
Bootstrap Tutorial
BOOTSTRAP TUTORIAL
tutorialspoint.com
i
Bootstrap Tutorial
Twitter Bootstrap is the most popular front end frameworks currently. It is sleek, intuitive, and powerful
mobile first front-end framework for faster and easier web development. It uses HTML, CSS and
Javascript.
This tutorial will teach you basics of Bootstrap Framework using which you can create web projects with
ease. Tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap
Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and
useful examples.
Audience
This tutorial has been prepared for anyone who has a basic knowledge of HTML and CSS and has an urge
to develop websites. After completing this tutorial you will find yourself at a moderate level of expertise
in developing web projects using Twitter Bootstrap.
Prerequisites
Before you start proceeding with this tutorial, I'm making an assumption that you are already aware
about basics of HTML and CSS. If you are not well aware of these concepts then I will suggest to go
through our short tutorial on HTML Tutorial and CSS Tutorial.
.
TUTORIALS POINT
Simply Easy Learning
Table of Content
Bootstrap Tutorial......................................................................2
Audience ...................................................................................2
Prerequisites .............................................................................2
Copyright & Disclaimer Notice ..................................................2
Bootstrap Overview.................................................................10
What is Twitter Bootstrap? ....................................................................... 10
History ...................................................................................................... 10
Why use Bootstrap? ................................................................................. 10
What Bootstrap Package Includes? ......................................................... 11
Containers ................................................................................................ 26
Pager ....................................................................................................... 97
DEFAULT PAGER .................................................................................. 97
ALIGNED LINKS ..................................................................................... 98
STATES .................................................................................................. 98
Bootstrap Jumpotron.............................................................102
TUTORIALS POINT
Simply Easy Learning
Options................................................................................................... 140
Methods ................................................................................................. 140
EXAMPLE .............................................................................................. 140
Options................................................................................................... 161
Methods ................................................................................................. 162
EXAMPLE .............................................................................................. 162
Events .................................................................................................... 163
EXAMPLE ............................................................................................. 164
TUTORIALS POINT
Simply Easy Learning
CHAPTER
Bootstrap Overview
What is Twitter Bootstrap?
ootstrap is a sleek, intuitive, and powerful mobile first front-end framework for faster and easier web
History
Bootstrap was developed by Mark Otto and Jacob Thornton at Twitter. It was released as an open source product
in August 2011 on GitHub.
Easy to get started: With just the knowledge of HTML and CSS anyone can get started with Bootstrap. Also
the Bootstrap official site has a good documentation.
Responsive design: Bootstrap's responsive CSS adjusts to Desktops,Tablets and Mobiles. More about
responsive design in the chapter Bootstrap Responsive Design
TUTORIALS POINT
Simply Easy Learning
Provides a clean and uniform solution for building an interface for developers.
It contains beautiful and functional built-in components which are easy to customize.
It also provides web based customization.
And best of all it is an open source.
TUTORIALS POINT
Simply Easy Learning
CHAPTER
t is very easy to setup and start using Bootstrap. This chapter will explain how to download and setup
Bootstrap. It will also discuss the Bootstrap file structure, and demonstrate its usage with an example.
Download Bootstrap
You can download the latest version of Bootstrap from http://getbootstrap.com/. When you click on this link, you
will get to see a screen as below:
TUTORIALS POINT
Simply Easy Learning
File structure
PRECOMPILED BOOTSTRAP
Once the compiled version Bootstrap is downloaded, extract the ZIP file, and you will see the following
file/directory structure:
As you can see there are compiled CSS and JS (bootstrap.*), as well as compiled and minified CSS and JS
(bootstrap.min.*). Fonts from Glyphicons are included, as is the optional Bootstrap theme.
The files under less/, js/, and fonts/ are the source code for Bootstrap CSS, JS, and icon fonts (respectively).
The dist/ folder includes everything listed in the precompiled download section above.
docs-assets/, examples/, and all *.html files are Bootstrap documentation.
HTML Template
A basic HTML template using Bootstrap would look like as this:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media
queries -->
<!-- WARNING: Respond.js doesn't work if you view the page
TUTORIALS POINT
Simply Easy Learning
Example
Now let's try an example using the above template. Try following example using Try it option available at the top
right corner of the below sample code box:
<h1>Hello, world!</h1>
In all the subsequent chapters we have used dummy text from the site http://www.lipsum.com/.
TUTORIALS POINT
Simply Easy Learning
CHAPTER
What is a Grid?
As put by wikepedia:
In graphic design, a grid is a structure (usually two-dimensional) made up of a series of intersecting straight
(vertical, horizontal) lines used to structure content. It is widely used to design layout and content structure in print
design. In web design, it is a very effective method to create a consistent layout rapidly and effectively using HTML
and CSS.
To put it simple words grids in web design organise and structure content, makes websites easy to scan and
reduces cognitive load on users.
Layout
TUTORIALS POINT
Simply Easy Learning
Base CSS address mobile device first;media queries address for tablet,desktops.
Progressive Enhancement
Media Queries
Media query is a really fancy term for "conditional CSS rule". It simply applies some CSS based on certain
conditions set forth. If those conditions are met, the style is applied.
Media Queries in Bootstrap allow you to move, show and hide content based on viewport size. Following media
queries are used in LESS files to create the key breakpoints in the Bootstrap grid system.
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { ... }
/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { ... }
/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { ... }
Occasionally these are expanded to include a max-width to limit CSS to a narrower set of devices.
@media
@media
@media
@media
(max-width:
(min-width:
(min-width:
(min-width:
@screen-xs-max)
@screen-sm-min)
@screen-md-min)
@screen-lg-min)
{ ... }
and (max-width: @screen-sm-max) { ... }
and (max-width: @screen-md-max) { ... }
{ ... }
Media queries have two parts, a device specification and then a size rule. In the above case, the following rule is
set:
Lets consider this line:
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
TUTORIALS POINT
Simply Easy Learning
For all devices no matter what kind with min-width: @screen-sm-min if the width of the screen gets smaller
than @screen-sm-max, then do something.
Grid options
The following table summarizes aspects of how Bootstrap grid system works across multiple devices:
Extra small devices
Phones (<768px)
Medium devices
Desktops (992px)
Large devices
Desktops (1200px)
Grid
behavior
Horizontal at all
times
Collapsed to start,
horizontal above
breakpoints
Collapsed to start,
horizontal above
breakpoints
Collapsed to start,
horizontal above
breakpoints
Max
container
width
None (auto)
750px
970px
1170px
Class prefix
.col-xs-
.col-sm-
.col-md-
.col-lg-
# of columns
12
12
12
12
Max column
width
Auto
60px
78px
95px
Gutter width
30px
(15px on each side
of a column)
30px
(15px on each side of a
column)
30px
(15px on each side of a
column)
30px
(15px on each side of a
column)
Nestable
Yes
Yes
Yes
Yes
Offsets
Yes
Yes
Yes
Yes
Column
ordering
Yes
Yes
Yes
Yes
TUTORIALS POINT
Simply Easy Learning
<div class="container">
<h1>Hello, world!</h1>
<div class="row">
<div class="col-md-6" style="background-color: #dedef8; box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa
quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo.
</p>
</div>
<div class="col-md-6" style="background-color: #dedef8;box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium.
</p>
<p> Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet,
consectetur, adipisci velit, sed quia non numquam eius modi
tempora incidunt ut labore et dolore magnam aliquam quaerat
voluptatem.
</p>
</div>
</div>
Details
<div class="container">...</div> element is added to ensure proper centering and maximum width for
layout.
Once container is added, next you need think in terms of rows. Add <div class="row">...</div>and
columns <div class="col-md-6"></div> inside rows.
Every row in the grid is made up of 12 units and you can define the desired size of your columns using those
units. In our example we have two columns each made of 6 units wide i.e 6+6=12.
You can try some more options like <div class="col-md-3"></div> and <div class="col-md-9"></div>or <div
class="col-md-7"></div> and <div class="col-md-5"></div>
Experiment and make sure that the sum always needs to be 12.
TUTORIALS POINT
Simply Easy Learning
<div class="col-md-6">....</div>
<div class="col-md-6">....</div>
But at large your design could really be better as a 33%/66%. So what were going to do is set it up to change the
column widths at the breakpoint:
<div class="col-md-6 col-lg-4">....</div>
<div class="col-md-6 col-lg-4">....</div>
Now Bootstrap is going to say at the medium size, I look at classes with md in them and use those. At the large
size, I look at classes with the word lg in them and use those. In this case, our 2 divs will go from a 50%/50% split
and then up to a 33%/66%. Check it out in the following example. (Here styling for each column is used. You can
avoid it.)
<div class="container">
<h1>Hello, world!</h1>
<div class="row">
<div class="col-md-6 col-lg-4" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa
quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo.
</p>
</div>
<div class="col-md-6 col-lg-8"" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium.
</p>
<p> Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet,
consectetur, adipisci velit, sed quia non numquam eius modi
tempora incidunt ut labore et dolore magnam aliquam quaerat
voluptatem.
</p>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
Offset columns
Offsets are a useful feature for more specialized layouts. They can be used to push columns over for more
spacing, for example. The .col-xs=* classes dont support offsets, but they are easily replicated by using an empty
cell.
To use offsets on large displays, use the .col-md-offset-* classes. These classes increase the left margin of a
column by * columns where * range from 1 to 11.
In the following example we have <div class="col-md-6">..</div>, we will center this using class .col-md-offset-3.
<div class="container">
<h1>Hello, world!</h1>
TUTORIALS POINT
Simply Easy Learning
Nesting columns
To nest your content with the default grid, add a new .row and set of .col-md-* columns within an existing .colmd-* column. Nested rows should include a set of columns that add up to 12.
In the following example, the layout has two columns, with the second one being split into four boxes over two
rows.
<div class="container">
<h1>Hello, world!</h1>
<div class="row">
<div class="col-md-3" style="background-color: #dedef8;box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<h4>First Column</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div class="col-md-9" style="background-color: #dedef8;box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<h4>Second Column- Split into 4 boxes</h4>
<div class="row">
<div class="col-md-6" style="background-color: #B18904;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Consectetur art party Tonx culpa semiotics. Pinterest
assumenda minim organic quis.
</p>
</div>
<div class="col-md-6" style="background-color: #B18904;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p> sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
<div class="row">
<div class="col-md-6" style="background-color: #B18904;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
TUTORIALS POINT
Simply Easy Learning
</p>
</div>
<div class="col-md-6" style="background-color: #B18904;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim.</p>
</div>
</div>
</div>
</div>
</div>
Column ordering
Another nice feature of Bootstrap grid system is that you can easily write the columns in an order, and show them
in another one. You can easily change the order of built-in grid columns with .col-md-push-* and .col-md-pull* modifier classes where * range from 1 to 11.
In the following example we have two-columns layout with left column being the narrowest and acting as sidebar.
We will swap the order of these columns using .col-md-push-* and .col-md-pull-* classes.
<div class="container">
<h1>Hello, world!</h1>
<div class="row">
<p>Before Ordering</p>
<div class="col-md-4" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
I am on left
</div>
<div class="col-md-8" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
I am on right
</div>
</div><br>
<div class="row">
<p>After Ordering</p>
<div class="col-md-4 col-md-push-8"
style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444,
inset -1px 1px 1px #444;">
I was on left
</div>
<div class="col-md-8 col-md-pull-4"
style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444,
inset -1px 1px 1px #444;">
I was on right
</div>
TUTORIALS POINT
Simply Easy Learning
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
n this chapter we will see an overview of the key pieces of Bootstrap's infrastructure, including Bootstrap's
HTML5 doctype
Bootstrap makes use of certain HTML elements and CSS properties that require the use of the HTML5 doctype.
Hence include the below piece of code for HTML5 doctype at the beginning of all your projects using Bootstrap.
<!DOCTYPE html>
<html>
....
</html>
Mobile First
Since Bootstrap 3, Bootstrap has become mobile first. It means mobile first styles can be found throughout the
entire library instead of in separate files. You need to add the viewport meta tag to the<head> element, to ensure
proper rendering and touch zooming on mobile devices.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
width property controls the width of the device. Setting it to device-width will make sure that it is rendered
across various devices (mobiles,desktops,tablets...) properly.
initial-scale=1.0 ensures that when loaded, your web page will be rendered at a 1:1 scale, and no zooming will
be applied out of the box.
Add user-scalable=no to the content attribute to disable zooming capabilities on mobile devices as shown below.
Users are only able to scroll and not zoom with this change, and results in your site feeling a bit more like a native
application.
<meta name="viewport" content="width=device-width,
initial-scale=1.0,
maximum-scale=1.0,
user-scalable=no">
Normally maximum-scale=1.0 is used along with user-scalable=no. As mentioned above user-scalable=no may
give users an experience more like a native app, hence Bootstrap doesn't recommend using this attribute.
TUTORIALS POINT
Simply Easy Learning
Responsive images
Bootstrap 3 allows to make the images responsive by adding a class .img-responsive to the <img>tag. This class
applies max-width: 100%; and height: auto; to the image so that it scales nicely to the parent element.
<img src="..." class="img-responsive" alt="Responsive image">
the
Normalize
Bootstrap uses Normalize to establish cross browser consistency.
Normalize.css is a modern, HTML5-ready alternative to CSS resets. It is a small CSS file that provides better
cross-browser consistency in the default styling of HTML elements.
Containers
Use class .container to wrap a page's content and easily center the content's as shown below.
<div class="container">
...
</div>
Take a look at the .container class in bootstrap.css file:
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
Note that, due to padding and fixed widths, containers are not nestable by default.
Take a look at bootstrap.css file:
@media (min-width: 768px) {
.container {
width: 750px;
}
Here you can see that CSS has media-queries for containers with width. This helps for applying responsiveness
and within those the container class is modified accordingly to render the grid system properly.
TUTORIALS POINT
Simply Easy Learning
CHAPTER
Bootstrap Typography
ootstrap uses Helvetica Neue, Helvetica, Arial, and sans-serif in its default font stack. Using typography
feature of Bootstrap you can create headings, paragraphs, lists and other inline elements. Let see each one these
in the following sections:
Headings
All HTML headings (h1 to h6) are styled in Bootstrap. An example is as shown below:
<h1>I'm
<h2>I'm
<h3>I'm
<h4>I'm
<h5>I'm
<h6>I'm
Heading1
Heading2
Heading3
Heading4
Heading5
Heading6
h1</h1>
h2</h2>
h3</h3>
h4</h4>
h5</h5>
h6</h6>
INLINE SUBHEADINGS
To add an inline subheading to any of the headings, simply add <small> around any of the elements or
add .small class and you will get smaller text in a lighter color as shown in the example below:
<h1>I'm Heading1 h1. <small>I'm secondary Heading1 h1</small></h1>
<h2>I'm Heading2 h2. <small>I'm secondary Heading2 h2</small></h2>
TUTORIALS POINT
Simply Easy Learning
<h3>I'm
<h4>I'm
<h5>I'm
<h6>I'm
Heading3
Heading4
Heading5
Heading6
h3.
h4.
h5.
h6.
<small>I'm
<small>I'm
<small>I'm
<small>I'm
secondary
secondary
secondary
secondary
Heading3
Heading4
Heading5
Heading1
h3</small></h3>
h4</small></h4>
h5</small></h5>
h6</small></h6>
Emphasis
HTML's default emphasis tags such as <<small> (sets text at 85% the size of the parent), <strong> emphasizes a
text with heavier font-weight, <em> emphasizes a text in italics.
Bootstrap offers a few classes that can be used to provide emphasis on texts as seen in the following example:
<small>This content is within <small> tag</small><br>
<strong>This content is within <strong> tag</strong><br>
<em>This content is within <em> tag and is rendered as italics</em><br>
<p class="text-left">Left aligned text.</p>
<p class="text-center">Center aligned text.</p>
<p class="text-right">Right aligned text.</p>
<p class="text-muted">This content is muted</p>
<p class="text-primary">This content carries a warning class</p>
<p class="text-success">This content carries a success class</p>
TUTORIALS POINT
Simply Easy Learning
Abbreviations
The HTML element provides markup for abbreviations or acronyms, like WWW or HTTP. Bootstrap styles <abbr>
elements with a light dotted border along the bottom and reveals the full text on hover (as long as you add that text
to the <abbr> title attribute). To get a a slightly smaller font size Add .initialism to <abbr>.
<abbr title="World Wide Web">WWW</abbr><br>
<abbr title="Real Simple Syndication" class="initialism">RSS</abbr>
Addresses
Using <address> tag you can display the contact information on your web page. Since the <address> defaults to
display:block;
youll
need
to
use
tags to add line breaks to the enclosed address text.
<address>
<strong>Some Company, Inc.</strong><br>
007 street<br>
Some City, State XXXXX<br>
<abbr title="Phone">P:</abbr> (123) 456-7890
</address>
<address>
<strong>Full Name</strong><br>
<a href="mailto:#">mailto@somedomain.com</a>
</address>
TUTORIALS POINT
Simply Easy Learning
Blockquotes
You can use the default <blockquote> around any HTML text. Other options include, adding a <small> tag for
identifying the source of the quote and right-aligning the blockquote using class .pull-right. The following example
demonstrates all these features:
<blockquote><p>
This is a default blockquote example. This is a default blockquote example. This is
a default blockquote example.This is a default blockquote example. This is a
default blockquote example.</p></blockquote>
<blockquote>This is a blockquote with a source title.<small>Someone famous in <cite
title="Source Title">Source Title</cite></small></blockquote>
<blockquote class="pull-right">This is a blockquote aligned to the
right.<small>Someone famous in <cite title="Source Title">Source
Title</cite></small></blockquote>
Lists
Bootstrap supports ordered lists, unordered lists, and definition lists.
Ordered lists: An ordered list is a list that falls in some sort of sequential order and is prefaced by numbers.
Unordered lists: An unordered list is a list that doesnt have any particular order and is traditionally styled with
bullets. If you do not want the bullets to appear then you can remove the styling by using the class .listunstyled. You can also place all list items on a single line using the class .list-inline.
Definition lists: In this type of list, each list item can consist of both the <dt> and the <dd> elements. <dt>
stands for definition term, and like a dictionary, this is the term (or phrase) that is being defined. Subsequently,
the <dd> is the definition of the <dt>.
You can make terms and descriptions in <dl> line up side-by-side using class dl-horizontal.
The following example demonstrates each of these types:
<h4>Example of Ordered List</h4>
<ol>
<li>Item 1</li>
TUTORIALS POINT
Simply Easy Learning
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ol>
<h4>Example of UnOrdered List</h4>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
<h4>Example of Unstyled List</h4>
<ul class="list-unstyled">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
<h4>Example of Inline List</h4>
<ul class="list-inline">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
<h4>Example of Definition List</h4>
<dl>
<dt>Description 1</dt>
<dd>Item 1</dd>
<dt>Description 2</dt>
<dd>Item 2</dd>
</dl>
<h4>Example of Horizontal Definition List</h4>
<dl class="dl-horizontal">
<dt>Description 1</dt>
<dd>Item 1</dd>
<dt>Description 2</dt>
<dd>Item 2</dd>
</dl>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
Bootstrap Code
ootstrap allows you to display code with two different key ways:
The first is the <code> tag. If you are going to be displaying code inline, you should use the <code> tag.
Second is the <pre> tag. If the code needs to be displayed as a standalone block element or if it has multiple
lines, then you should use the <pre> tag.
Make sure that when you use the <pre> and <code> tags, you use the unicode variants for the opening and
closing tags: < and >.
Let us see an example below:
<p><code><header></code> is wrapped as an inline element.</p>
<p>To display code as a standalone block element use <pre> tag as:
<pre>
<article>
<h1>Article Heading</h1>
</article>
</pre>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
Bootstrap Tables
ootstrap provides a clean layout for building tables. Some of the table elements supported by Bootstrap
are:
Tag
Description
<table>
<thead>
Container element for table header rows (<tr>) to label table columns
<tbody>
Container element for table rows (<tr>) in the body of the table
<tr>
Container element for a set of table cells (<td> or <th>) that appears on a single row
<td>
<th>
Special table cell for column (or row, depending on scope and placement) labels. Must be used within a
<thead>
Basic Table
If you want a nice, basic table style with just some light padding and horizontal dividers, add the base class
of .table to any table as shown in the following example:
<table class="table">
<caption>Basic Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanmay</td>
<td>Bangalore</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
TUTORIALS POINT
Simply Easy Learning
</tr>
</tbody>
</table>
STRIPED TABLE
By adding the .table-striped class, you will get stripes on rows within the <tbody> as seen in the following example:
<table class="table table-striped">
<caption>Striped Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>City</th>
<th>Pincode</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanmay</td>
<td>Bangalore</td>
<td>560001</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
<td>400003</td>
</tr>
<tr>
<td>Uma</td>
<td>Pune</td>
<td>411027</td>
</tr>
</tbody>
</table>
TUTORIALS POINT
Simply Easy Learning
BORDERED TABLE
By adding the .table-bordered class, you will get borders surrounding every element and rounded corners around
the entire table as seen in the following example:
<table class="table table-bordered">
<caption>Bordered Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>City</th>
<th>Pincode</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanmay</td>
<td>Bangalore</td>
<td>560001</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
<td>400003</td>
</tr>
<tr>
<td>Uma</td>
<td>Pune</td>
<td>411027</td>
</tr>
</tbody>
</table>
HOVER TABLE
By adding the .table-hover class, a light gray background will be added to rows while the cursor hovers over them,
as seen in the following example:
<table class="table table-hover">
<caption>Hover Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>City</th>
<th>Pincode</th>
</tr>
</thead>
<tbody>
<tr>
TUTORIALS POINT
Simply Easy Learning
<td>Tanmay</td>
<td>Bangalore</td>
<td>560001</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
<td>400003</td>
</tr>
<tr>
<td>Uma</td>
<td>Pune</td>
<td>411027</td>
</tr>
</tbody>
</table>
CONDENSED TABLE
By adding the .table-condensed class, row padding is cut in half to condense the table. as seen in the following
example. This is useful if you want denser information.
<table class="table table-condensed">
<caption>Condensed Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>City</th>
<th>Pincode</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanmay</td>
<td>Bangalore</td>
<td>560001</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
<td>400003</td>
</tr>
<tr>
<td>Uma</td>
<td>Pune</td>
<td>411027</td>
</tr>
</tbody>
</table>
TUTORIALS POINT
Simply Easy Learning
Contextual classes
The Contextual classes shown in following table will allow you to change the background color of your table rows
or individual cells.
Class
Description
.active
.success
.warning
.danger
TUTORIALS POINT
Simply Easy Learning
Responsive tables
By wrapping any .table in .table-responsive class, you will make the table scroll horizontally up to small devices
(under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.
<div class="table-responsive">
<table class="table">
<caption>Responsive Table Layout</caption>
<thead>
<tr>
<th>Product</th>
<th>Payment Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Product1</td>
<td>23/11/2013</td>
<td>Pending</td>
</tr>
<tr>
<td>Product2</td>
<td>10/11/2013</td>
<td>Delivered</td>
</tr>
<tr>
<td>Product3</td>
<td>20/10/2013</td>
<td>In Call to confirm</td>
</tr>
<tr>
<td>Product4</td>
<td>20/10/2013</td>
<td>Declined</td>
</tr>
</tbody>
</table>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
Bootstrap Forms
n this chapter we will study how to create forms with ease using Bootstrap. Bootstrap makes it easy with the
simple HTML markup and extended classes for different styles of forms.
Form Layout
Bootstrap provides you with following types of form layouts:
Vertical (default) form
Inline form
Horizontal form
TUTORIALS POINT
Simply Easy Learning
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
INLINE FORM
To create a form where all of the elements are inline, left aligned and labels are alongside, add the class .forminline to the <form> tag.
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="name">Name</label>
<input type="text" class="form-control" id="name"
placeholder="Enter Name">
</div>
<div class="form-group">
<label class="sr-only" for="inputfile">File input</label>
<input type="file" id="inputfile">
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
By default Inputs, selects, and textareas have 100% width in Bootstrap. You need to set a width on the form
controls when using inline form.
Using the class .sr-only you can hide the labels of the inline forms.
HORIZONTAL FORM
Horizontal forms stands apart from the others not only in the amount of markup, but also in the presentation of the
form. To create a form that uses the horizontal layout, do the following:
Add a class of .form-horizontal to the parent <form> element.
Wrap labels and controls in a <div> with class .form-group.
Add a class of .control-label to the labels.
TUTORIALS POINT
Simply Easy Learning
INPUTS
The most common form text field is the inputthis is where users will enter most of the essential form data.
Bootstrap offers support for all native HTML5 input types: text, password, datetime, datetime-local, date, month,
time, week, number, email, url, search, tel, and color. Proper type declaration is required to make Inputs fully
styled.
<form role="form">
<div class="form-group">
<label for="name">Label</label>
<input type="text" class="form-control" placeholder="Text input">
</div>
</form>
TUTORIALS POINT
Simply Easy Learning
TEXTAREA
The textarea is used when you need multiple lines of input. Change rows attribute as necessary (fewer rows =
smaller box, more rows = bigger box).
<form role="form">
<div class="form-group">
<label for="name">Text Area</label>
<textarea class="form-control" rows="3"></textarea>
</div>
</form>
TUTORIALS POINT
Simply Easy Learning
SELECTS
A select is used when you want to allow the user to pick from multiple options, but by default it only allows one.
Use <select> for list options with which the user is familiar, such as states or numbers.
Use multiple="multiple" to allow the user to select more than one option.
The following example demonstrates both (select and multiple) types:
<form role="form">
<div class="form-group">
<label for="name">Select list</label>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<label for="name">Mutiple Select list</label>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</form>
TUTORIALS POINT
Simply Easy Learning
Static control
Use the class .form-control-static on a <p>, when you need to place plain text next to a form label within a
horizontal form.
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<p class="form-control-static">email@example.com</p>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword"
placeholder="Password">
</div>
</div>
</form>
INPUT FOCUS
When an input receives :focus, the outline of the input is removed and a box-shadow is applied.
DISABLED INPUTS
If you need to disable an input, simply adding the disabled attribute will not only disable it; it will also change the
styling and the mouse cursor when the cursor hovers over the element.
DISABLED FIELDSETS
Add the disabled attribute to a <fieldset> to disable all the controls within the <fieldset> at once.
VALIDATION STATES
Bootstrap includes validation styles for error, warning, and success messages. To use, simply add the appropriate
class (.has-warning, .has-error, or .has-success) to the parent element.
Following example demonstrates all the form control states:
<form class="form-horizontal" role="form">
<div class="form-group">
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
</form>
TUTORIALS POINT
Simply Easy Learning
Help Text
Bootstrap form controls can have a block level help text that flows with the inputs. To add a full width block of
content, use the .help-block after the <input>. Following example demonstrates this:
<form role="form">
<span>Example of Help Text</span>
<input class="form-control" type="text" placeholder="">
<span class="help-block">A longer block of help text that
breaks onto a new line and may extend beyond one line.</span>
</form>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
Bootstrap Buttons
his chapter will discuss about how to use Bootstrap button with examples. Anything that is given a class
of .btn will inherit the default look of a gray button with rounded corners. However Bootstrap provides some
options to style buttons, which are summarized in the following table:
Class
Description
Btn
btn-primary
Provides extra visual weight and identifies the primary action in a set of buttons.
btn-success
btn-info
btn-warning
btn-danger
btn-link
Deemphasize a button by making it look like a link while maintaining button behavior.
TUTORIALS POINT
Simply Easy Learning
<!-- Deemphasize a button by making it look like a link while maintaining button
behavior -->
<button type="button" class="btn btn-link">Link Button</button>
Button Size
The following table summarizes classes used to get buttons of various sizes:
Class
Description
.btn-lg
.btn-sm
.btn-xs
.btn-block
This creates block level buttonsthose that span the full width of a parent.
TUTORIALS POINT
Simply Easy Learning
btn-primary btn-lg">
btn-default btn-lg"
btn-primary">
btn-default">
btn-primary btn-sm">
btn-default btn-sm">
btn-primary btn-xs">
btn-default btn-xs">
Button State
Bootstrap provides classes which allow you change the state of buttons say active, disabled etc each of these are
discussed in the following sections:
ACTIVE STATE
Buttons will appear pressed (with a darker background, darker border, and inset shadow) when active. The
following table summarizes classes used to make button element and anchor element active:
Element
Class
Button element
Anchor element
TUTORIALS POINT
Simply Easy Learning
DISABLED STATE
When you disable a button, it will fade in color by 50%, and lose the gradient.
The following table summarizes classes used to make button element and anchor element disabled:
Element
Class
Button element
Anchor element
TUTORIALS POINT
Simply Easy Learning
</a>
</p>
Button Tags
You may use button classes with <a>, <button>, or <input> element. But it is recommended that you use it with
<button> elements mostly to avoid cross browser inconsistency issues.
The following example demonstrates this:
<a class="btn btn-default" href="#" role="button">Link</a>
<button class="btn btn-default" type="submit">Button</button>
<input class="btn btn-default" type="button" value="Input">
<input class="btn btn-default" type="submit" value="Submit">
TUTORIALS POINT
Simply Easy Learning
CHAPTER
10
Bootstrap Images
n this chapter we will learn Bootstrap support for images. Bootstrap provides three classes that can be used to
TUTORIALS POINT
Simply Easy Learning
CHAPTER
11
Bootstrap Helper Classes
his chapter discusses some of the helper classes in Bootstrap that might come in handy.
Close icon
Use the generic close icon for dismissing content like modals and alerts. Use the class close to get the close icon.
<p>Close Icon Example
<button type="button" class="close" aria-hidden="true">
×
</button>
</p>
Carets
Use carets to indicate dropdown functionality and direction. To get this functionality use the class caretwith a
<span> element.
<p>Caret Example
<span class="caret"></span>
</p>
Quick floats
You can float an element to the left or right with class pull-left or pull-right respectively. Following example
demonstrates this.
<div class="pull-left">
Quick Float to left
</div>
<div class="pull-right">
Quick Float to right
</div>
TUTORIALS POINT
Simply Easy Learning
To align components in navbars with utility classes, use .navbar-left or .navbar-right instead. See the navbar
chapter for details.
Clearfix
To clear the float of any element, use the .clearfix class.
<div class="clearfix" style="background: #D8D8D8;border: 1px solid #000;padding:
10px;">
<div class="pull-left" style="background:#58D3F7;">
Quick Float to left
</div>
<div class="pull-right" style="background: #DA81F5;">
Quick Float to right
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
Here we can see that the label of both the input types is assigned the class sr-only, hence labels will be visible to
only screen readers.
TUTORIALS POINT
Simply Easy Learning
CHAPTER
12
Bootstarp Responsive
Utilities
ootstrap provides some handful helper classes, for faster mobile-friendly development. These can be
used for showing and hiding content by device via media query combined with large, small, and medium devices.
Use these sparingly and avoid creating entirely different versions of the same site. Responsive utilities are
currently only available for block and table toggling.
Classes
Devices
.visible-xs
.visible-sm
.visible-md
.visible-lg
.hidden-xs
.hidden-sm
.hidden-md
.hidden-lg
Print classes
Following table lists the print classes. Use these for toggling content for print.
Classes
.visible-print
Yes Visible
.hidden-print
TUTORIALS POINT
Simply Easy Learning
Example
Following example demonstrates the use of above listed helper classes. Resize your browser or load the example
on different devices to test the responsive utility classes.
<div class="container" style="padding: 40px;">
<div class="row visible-on">
<div class="col-xs-6 col-sm-3" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<span class="hidden-xs">Extra small</span>
<span class="visible-xs"> Visible on x-small</span>
</div>
<div class="col-xs-6 col-sm-3" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<span class="hidden-sm">Small</span>
<span class="visible-sm"> Visible on small</span>
</div>
<div class="clearfix visible-xs"></div>
<div class="col-xs-6 col-sm-3" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<span class="hidden-md">Medium</span>
<span class="visible-md"> Visible on medium</span>
</div>
<div class="col-xs-6 col-sm-3" style="background-color: #dedef8;
box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<span class="hidden-lg">Large</span>
<span class="visible-lg"> Visible on large</span>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
13
Bootstrap Glyphicons
his chapter will discuss about Glyphicons, its use and some examples. Bootstrap bundles 200 glyphs in
Usage
To use the icons, simply use the following code just about anywhere in your code. Leave a space between the icon
and text for proper padding.
<span class="glyphicon glyphicon-search"></span>
Following example demonstrates this:
<p>
<button type="button" class="btn btn-default">
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
14
Bootstrap Dropdowns
his chapter will highlight about Bootstrap dropdown menus. Dropdown menus are toggleable, contextual
menus for displaying links in a list format. This can be made interactive with the dropdown JavaScript plugin.
To use dropdown, just wrap the dropdown menu within the class .dropdown. Following example demonstrates a
basic dropdown menu:
<div class="dropdown">
<button type="button" class="btn dropdown-toggle" id="dropdownMenu1"
data-toggle="dropdown">
Topics
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Java</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Data Mining</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
Data Communication/Networking
</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Separated link</a>
</li>
</ul>
</div>
TUTORIALS POINT
Simply Easy Learning
OPTIONS
ALIGNMENT
Align the dropdown menu to right by adding the class .pull-right to .dropdown-menu. Following example
demonstrates this:
<div class="dropdown">
<button type="button" class="btn dropdown-toggle" id="dropdownMenu1"
data-toggle="dropdown">Topics
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" role="menu"
aria-labelledby="dropdownMenu1">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Java</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Data Mining</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
Data Communication/Networking
</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Separated link</a>
</li>
</ul>
</div>
HEADERS
You can add a header to label sections of actions in any dropdown menu by using the classdropdown-header.
Following example demonstrates this:
TUTORIALS POINT
Simply Easy Learning
<div class="dropdown">
<button type="button" class="btn dropdown-toggle" id="dropdownMenu1"
data-toggle="dropdown">
Topics
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation" class="dropdown-header">Dropdown header</li>
<li role="presentation" >
<a role="menuitem" tabindex="-1" href="#">Java</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Data Mining</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
Data Communication/Networking
</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation" class="dropdown-header">Dropdown header</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Separated link</a>
</li>
</ul>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
15
Bootstrap Button Groups
utton groups allow multiple buttons to be stacked together on a single line. This is useful when you want
to place items like alignment buttons together. You can add on optional JavaScript radio and checkbox style
behavior with Bootstrap Button Plugin.
Following table summarizes the important classes Bootstrap provides to use button groups:
Class
Description
Code Sample
.btn-group
<div class="btn-group">
<button type="button" class="btn
btn-default">Button1</button>
<button type="button" class="btn
btn-default">Button2</button>
</div>
.btn-toolbar
This helps to combine sets of <div class="btngroup"> into a <div class="btn-toolbar"> for
more complex components.
<div class="btn-toolbar"
role="toolbar">
<div class="btn-group">...</div>
<div class="btn-group">...</div>
</div>
.btn-group-lg,
.btn-group-sm,
.btn-group-xs
.btn-groupvertical
<div class="btn-group-vertical">
...
</div>
TUTORIALS POINT
Simply Easy Learning
Button Toolbar
Following examples demonstrates the use of class .btn-toolbar discussed in the above table:
<div class="btn-toolbar" role="toolbar">
<div class="btn-group">
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
</div>
</div>
1</button>
2</button>
3</button>
4</button>
5</button>
6</button>
7</button>
8</button>
9</button>
Button Size
Following examples demonstrates the use of class .btn-group-* discussed in the above table:
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
</div>
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
</div>
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
<button type="button" class="btn btn-default">Button
</div>
TUTORIALS POINT
Simply Easy Learning
1</button>
2</button>
3</button>
4</button>
5</button>
6</button>
7</button>
8</button>
9</button>
Nesting
You can nest button groups within another button group i.e, place a .btn-group within another .btn-group . This is
done when you want dropdown menus mixed with a series of buttons.
<div class="btn-group">
<button type="button" class="btn btn-default">Button 1</button>
<button type="button" class="btn btn-default">Button 2</button>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Dropdown link 1</a></li>
<li><a href="#">Dropdown link 2</a></li>
</ul>
</div>
</div>
Vertical Buttongroup
Following examples demonstrates the use of class .btn-group-vertical discussed in the above table:
<div class="btn-group-vertical">
<button type="button" class="btn btn-default">Button 1</button>
<button type="button" class="btn btn-default">Button 2</button>
<div class="btn-group-vertical">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Dropdown link 1</a></li>
<li><a href="#">Dropdown link 2</a></li>
</ul>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
16
Bootstrap Button Dropdowns
his chapter will discuss about how to add dropdown menu to buttons using Bootstrap classes. To add a
dropdown to a button, simply wrap the button and dropdown menu in a .btn-group. You can also use <span
class="caret"></span> to act as an indicator that the button is a dropdown.
The following example demonstrates a basic single button dropdowns:
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown">
Default <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle"
data-toggle="dropdown">
Primary <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
data-toggle="dropdown">
Primary <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle btn-xs"
data-toggle="dropdown">
Success <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
Dropup variation
Menus can also be built to drop up rather than down. To achieve this, simply add .dropup to the parent.btngroup container.
<div class="row" style="margin-left:50px; margin-top:200px">
<div class="btn-group dropup">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown">
Default <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<div class="btn-group dropup">
<button type="button" class="btn btn-primary dropdown-toggle"
data-toggle="dropdown">
Primary <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
TUTORIALS POINT
Simply Easy Learning
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
17
Bootstrap Input Groups
his chapter explains about one more feature Bootstrap supports, the Input Groups. Input groups are
extended Form Controls. Using input groups you can easily prepend and append text or buttons to text-based
inputs.
By adding prepended and appended content to an input field, you can add common elements to the users input.
For example, you can add the dollar symbol, the @ for a Twitter username, or anything else that might be common
for your application interface.
To prepend or append elements to a .form-control:
Wrap it in a <div> with class .input-group
As a next step, within that same <div> , place your extra content inside a <span> with class.input-groupaddon.
Now place this <span> either before or after the <input> element.
For cross browser compatibility, avoid using <select> elements here as they cannot be fully styled in WebKit
browsers. Also do not apply input group classes directly to form groups. An input group is an isolated component.
TUTORIALS POINT
Simply Easy Learning
</div>
</form>
</div>
TUTORIALS POINT
Simply Easy Learning
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
</span>
<input type="text" class="form-control">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 --><br>
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">
<input type="radio">
</span>
<input type="text" class="form-control">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</form>
</div>
Button addons
You can even preappend or append buttons in input groups. Instead of .input-group-addon class, you'll need to
use class .input-group-btn to wrap the buttons. This is required due to default browser styles that cannot be
overridden. Following examples demonstrates this:
<div style="padding: 100px 100px 10px;">
<form class="bs-example bs-example-form" role="form">
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
Go!
</button>
</span>
<input type="text" class="form-control">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 --><br>
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
Go!
</button>
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</form>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
Segmented buttons
To segment button dropdowns in input groups, use the same general style as the dropdown button but add a
primary action along with the dropdown as can be seen in the following example:
<div style="padding: 100px 100px 10px;">
<form class="bs-example bs-example-form" role="form">
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default"
tabindex="-1">Dropdwon Menu
</button>
<button type="button" class="btn btn-default
dropdown-toggle" data-toggle="dropdown" tabindex="-1">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<input type="text" class="form-control">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 --><br>
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn">
<button type="button" class="btn btn-default"
tabindex="-1">Dropdwon Menu
</button>
<button type="button" class="btn btn-default
dropdown-toggle" data-toggle="dropdown" tabindex="-1">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu pull-right">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
18
Bootstrap Navigation Elements
n this chapter we will discuss about how Bootstrap provides a few different options for styling navigation
elements. All of them share the same markup and base class, .nav. Bootstrap also provides a helper class, to
share markup and states. Swap modifier classes to switch between each style.
Pills Navigation
BASIC PILLS
To turn the tabs into pills, follow the same steps as above, use the class .nav-pills instead of .nav-tabs.
Following example demonstrates this:
<p>Pills Example</p>
TUTORIALS POINT
Simply Easy Learning
VERTICLE PILLS
You can stack the pills vertically using the class .nav-stacked alongwith classes .nav, .nav-pills.
Following example demonstrates this:
<p>Vertical Pills Example</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>
Justified Nav
You can make tabs or pills equal widths of their parent at screens wider than 768px using class .navjustified alongwith .nav, .nav-tabs or .nav, .nav-pills respectively. On smaller screens, the nav links are stacked.
Following example demonstrates this:
<p>Justified Nav Elements Example</p>
<ul class="nav nav-pills nav-justified">
<li class="active"><a href="#">Home</a></li>
TUTORIALS POINT
Simply Easy Learning
<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>
Disabled Links
For each of the .nav classes, if you add the .disabled class, it will create a gray link that also disables
the :hover state as shown in the following example:
<p>Disabled Link Example</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>
TUTORIALS POINT
Simply Easy Learning
This class will only change the <a>'s appearance, not its functionality. Use custom JavaScript to disable links here.
DROPDOWNS
Navigation menus share a similar syntax with dropdown menus. By default, you have a list item that has an anchor
working in conjunction with some data-attributes to trigger an unordered list with a.dropdown-menu class.
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
19
Bootstrap Navbar
he Navbar is a nice feature, and is one of the prominent features of Bootstrap sites. Navbars are
responsive meta components that serve as navigation headers for your application or site. Navbars collapse in
mobile views and become horizontal as the available viewport width increases. At its core, the navbar includes
styling for site names and basic navigation.
Default navbar
To create a default navbar:
Add classes .navbar, .navbar-default to the <nav> tag.
Add role="navigation" to the above element, to help with accessibility.
Add a header class .navbar-header to the <div> element. Include an <a> element with classnavbar-brand.
This will give the text a slightly larger size.
To add links to the navbar, simply add an unordered list with a classes of .nav, .navbar-nav.
Following example demonstrates this:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</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="#">One more separated link</a></li>
</ul>
</li>
TUTORIALS POINT
Simply Easy Learning
</ul>
</div>
</nav>
Responsive navbar
To add the responsive features to the navbar, the content that you want to be collapsed needs to be wrapped in a
<div> with classes .collapse, .navbar-collapse. The collapsing nature is tripped by a button that has a the class
of .navbar-toggle and then features two data- elements. The first, data-toggle, is used to tell the JavaScript what
to do with the button, and the second, data-target, indicates which element to toggle. Three with a class of .iconbar create what I like to call the hamburger button. This will toggle the elements that are in the .navcollapse <div>. For this feature to work, you need to include the Bootstrap Collapse Plugin.
Following example demonstrates this:
<nav class="navbar navbar-default" role="navigation">
<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="#">TutorialsPoint</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="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
</nav>
TUTORIALS POINT
Simply Easy Learning
Forms in navbar
Instead of using the default class-based forms from Chapter Bootstrap Forms, forms that are in the navbar use
the .navbar-form class. This ensures that the forms proper vertical alignment and collapsed behavior in narrow
viewports. Use the alignment options (explained in Component alignment section) to decide where it resides within
the navbar content.
Following example demonstrates this:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<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>
Buttons in navbar
You can add buttons using class .navbar-btn to <button> elements not residing in a <form> to vertically center
them in the navbar. .navbar-btn can be used on <a> and <input> elements.
TUTORIALS POINT
Simply Easy Learning
Do not use .navbar-btn nor the standard button classes on <a> elements within .navbar-nav.
Following example demonstrates this:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<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</button>
</form>
<button type="button" class="btn btn-default navbar-btn">
Navbar Button
</button>
</div>
</nav>
Text in navbar
To wrap strings of text in an element use class .navbar-text. This is usually used with <p> tag for proper leading
and color. Following example demonstrates this:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<div>
<p class="navbar-text">Signed in as Thomas</p>
</div>
</nav>
Non-nav links
If you want to use standard links that are not within the regular navbar navigation component, then use
class navbar-link to add the proper colors for the default and inverse navbar options as shown in the following
example:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<div>
<p class="navbar-text navbar-right">Signed in as
<a href="#" class="navbar-link">Thomas</a>
TUTORIALS POINT
Simply Easy Learning
</p>
</div>
</div>
Component alignment
You can align the components like nav links, forms, buttons, or text to left or right in a navbar using the utility
classes .navbar-left or .navbar-right. Both classes will add a CSS float in the specified direction. The following
example demonstrates this:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<div>
<!--Left Align-->
<ul class="nav navbar-nav navbar-left">
<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="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<button type="submit" class="btn btn-default">
Left align-Submit Button
</button>
</form>
<p class="navbar-text navbar-left">Left align-Text</p>
<!--Right Align-->
<ul class="nav navbar-nav navbar-right">
<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="#">One more separated link</a></li>
</ul>
TUTORIALS POINT
Simply Easy Learning
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<button type="submit" class="btn btn-default">
Right align-Submit Button
</button>
</form>
<p class="navbar-text navbar-right">Right align-Text</p>
</div>
</nav>
Fixed to top
The Bootstrap navbar can be dynamic in its positioning. By default, it is a block-level element that takes its
positioning based on its placement in the HTML. With a few helper classes, you can place it either on the top or
bottom of the page, or you can make it scroll statically with the page.
If you want the navbar fixed to the top, add class .navbar-fixed-top to the .navbar class. Following example
demonstrates this:
To prevent the navbar from sitting on top of other content in the body of the page, add at least 50 pixels of padding
to the <body> tag or try your own values.
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</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="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
</nav>
TUTORIALS POINT
Simply Easy Learning
Fixed to bottom
If you want the navbar fixed to the bottom of the page, add class .navbar-fixed-bottom to the .navbar class.
Following example demonstrates this:
<nav class="navbar navbar-default navbar-fixed-bottom" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</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="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
</nav>
Static top
To create a navbar that scrolls with the page, add the .navbar-static-top class. This class does not require adding
the padding to the <body>.
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</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>
TUTORIALS POINT
Simply Easy Learning
Inverted navbar
To create an inverted navbar with a black background and white text, simply add .navbar-inverse class to
the .navbar class as demonstrated in the following example:
To prevent the navbar from sitting on top of other content in the body of the page, add at least 50 pixels of padding
to the <body> tag or try your own values.
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</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="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
</nav>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
20
Bootstrap Breadcrumb
readcrumbs are a great way to show hierarchy-based information for a site. In the case of blogs,
breadcrumbs can show the dates of publishing, categories, or tags. They indicate the current page's location within
a navigational hierarchy.
A breadcrumb in Bootstrap is simply an unordered list with a class of .breadcrumb. The separator is automatically
added by CSS (bootstrap.min.css) through the following class:
.breadcrumb > li + li:before {
color: #CCCCCC;
content: "/ ";
padding: 0 5px;
}
Following example demonstrates breadcrumbs:
<ol class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">2013</a></li>
<li class="active">November</li>
</ol>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
21
Bootstrap Pagination
his chapter discusses about pagination feature Bootstrap supports. Pagination, an unordered list is
Pagination
The following table lists the classes Bootstrap provides to handle pagination.
Class
.pagination
.disabled,
.active
.pagination-lg,
.paginationsm
Description
Sample code
<ul class="pagination">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
.......
</ul>
<ul class="pagination">
<li class="disabled"><a
href="#">«</a></li>
<li class="active"><a href="#">1<span
class="sronly">(current)</span></a></li>
.......
</ul>
DEFAULT PAGINATION
Following example demonstrates the use of class .pagination discussed in the above table:
<ul class="pagination">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
TUTORIALS POINT
Simply Easy Learning
<li><a
<li><a
<li><a
<li><a
<li><a
</ul>
href="#">2</a></li>
href="#">3</a></li>
href="#">4</a></li>
href="#">5</a></li>
href="#">»</a></li>
STATES
Following example demonstrates the use of class .disabled, .active discussed in the above table:
<ul class="pagination">
<li><a href="#">«</a></li>
<li class="active"><a href="#">1</a></li>
<li class="disabled"><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
SIZING
Following example demonstrates the use of classes for sizing, .pagination-* discussed in the above table:
<ul class="pagination pagination-lg">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul><br>
<ul class="pagination">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul><br>
<ul class="pagination pagination-sm">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
TUTORIALS POINT
Simply Easy Learning
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
Pager
If you need to create simple pagination links that go beyond text, the pager can work quite well. Like the pagination
links, the pager is an unordered list. By default the links are centered. The following table lists the classes
Bootstrap provides for pager.
Class
Description
Sample code
.pager
<ul class="pager">
<li><a href="#">Previous</a></li>
<li><a href="#">Next</a></li>
</ul>
<ul class="pager">
<li class="previous"><a
href="#">← Older</a></li>
<li class="next"><a href="#">Newer
→</a></li>
</ul>
<ul class="pager">
<li class="previous disabled"><a
href="#">← Older</a></li>
<li class="next"><a href="#">Newer
→</a></li>
</ul>
.previous,
.next
.disabled
DEFAULT PAGER
Following example demonstrates the use of class .pager discussed in the above table:
<ul class="pager">
<li><a href="#">Previous</a></li>
<li><a href="#">Next</a></li>
</ul>
TUTORIALS POINT
Simply Easy Learning
ALIGNED LINKS
Following example demonstrates the use of classes for alignment, .previous, .next discussed in the above table:
<ul class="pager">
<li class="previous"><a href="#">← Older</a></li>
<li class="next"><a href="#">Newer →</a></li>
</ul>
STATES
Following example demonstrates the use of class .disabled discussed in the above table:
<ul class="pager">
<li class="previous disabled"><a href="#">← Older</a></li>
<li class="next"><a href="#">Newer →</a></li>
</ul>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
22
Bootstrap Labels
his chapter will discuss about Bootstrap labels. Labels are great for offering counts, tips, or other markup
for pages. Use class .label to display labels as shown in the following example:
<h1>Example
<h2>Example
<h3>Example
<h4>Example
Heading
Heading
Heading
Heading
<span
<span
<span
<span
class="label
class="label
class="label
class="label
label-default">Label</span></h1>
label-default">Label</span></h2>
label-default">Label</span></h3>
label-default">Label</span></h4>
You can the appearance of the labels using the modifier classes label-default, label-primary, label-success,
label-info, label-warning, label-danger as shown in the following example:
<span
<span
<span
<span
<span
<span
class="label
class="label
class="label
class="label
class="label
class="label
label-default">Default Label</span>
label-primary">Primary Label</span>
label-success">Success Label</span>
label-info">Info Label</span>
label-warning">Warning Label</span>
label-danger">Danger Label</span>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
23
Bootstrap Badges
his chapter will discuss about Bootstrap badges. Badges are similar to labels; the primary difference is
When there are no new or unread items, badges will simply collapse via CSS's :empty selector provided no
content exists within.
TUTORIALS POINT
Simply Easy Learning
</a>
</li>
</ul>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
24
Bootstrap Jumpotron
his chapter will discuss one more feature Bootstrap supports, the Jumbotron. As the name suggest this
component can optionally increases the size of headings and add a lot of margin for landing page content. To use
the Jumbotron:
simply create a container <div> with the class of .jumbotron.
In addition to a larger <h1>, the font-weight is reduced to 200px.
The following example demonstrates this:
<div class="container">
<div class="jumbotron">
<h1>Welcome to landing page!</h1>
<p>This is an example for jumbotron.</p>
<p><a class="btn btn-primary btn-lg" role="button">
Learn more</a>
</p>
</div>
</div>
To get a jumbotron full width, and without rounded corners use the .jumbotron class outside all.container classes
and instead add a .container within as shown in the following example:
TUTORIALS POINT
Simply Easy Learning
<div class="jumbotron">
<div class="container">
<h1>Welcome to landing page!</h1>
<p>This is an example for jumbotron.</p>
<p><a class="btn btn-primary btn-lg" role="button">
Learn more</a>
</p>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
25
Bootstrap Page Header
he page header is a nice little feature to add appropriate spacing around the headings on a page. This is
particularly helpful on a web page where you may have several post titles and need a way to add distinction to
each of them. To use a page header, wrap your heading in a <div> with a class of.page-header:
<div class="page-header">
<h1>Example page header
<small>Subtext for header</small>
</h1>
</div>
<p>This is a sample text.This is a sample text.This is a sample text.
This is a sample text.</p>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
26
Bootstrap Thumbnails
his chapter discusses about Bootstrap thumbnails. A lot of sites need a way to lay out images,videos,text,
etc in a grid, and Bootstrap has an easy way to do this with thumbnails. To create thumbnails using Bootstrap:
Add an <a> tag with the class of .thumbnail around an image.
This adds four pixels of padding and a gray border.
On hover, an animated glow outlines the image.
The following example demonstrates a default thumbnail:
<div class="row">
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="/bootstrap/images/kittens.jpg"
alt="Generic placeholder thumbnail">
</a>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="/bootstrap/images/kittens.jpg"
alt="Generic placeholder thumbnail">
</a>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="/bootstrap/images/kittens.jpg"
alt="Generic placeholder thumbnail">
</a>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="/bootstrap/images/kittens.jpg"
alt="Generic placeholder thumbnail">
</a>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
</div>
<div class="col-sm-6 col-md-3">
<div class="thumbnail">
<img src="/bootstrap/images/kittens.jpg"
alt="Generic placeholder thumbnail">
</div>
<div class="caption">
<h3>Thumbnail label</h3>
<p>Some sample text. Some sample text.</p>
<p>
<a href="#" class="btn btn-primary" role="button">
Button
</a>
<a href="#" class="btn btn-default" role="button">
Button
</a>
</p>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="thumbnail">
<img src="/bootstrap/images/kittens.jpg"
alt="Generic placeholder thumbnail">
</div>
<div class="caption">
<h3>Thumbnail label</h3>
<p>Some sample text. Some sample text.</p>
<p>
<a href="#" class="btn btn-primary" role="button">
Button
</a>
<a href="#" class="btn btn-default" role="button">
Button
</a>
</p>
</div>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
27
Bootstrap Alerts
his chapter will discuss about alerts and the classes Bootstrap provides for alerts. Alerts provide a way to
style messages to the user. They provide contextual feedback messages for typical user actions.
You can add an optional close icon to alert. For inline dismissal use the Alerts jQuery plugin.
You can add an basic alert by creating a wrapper <div> and adding a class of .alert and one of the four contextual
classes (e.g., .alert-success, .alert-info, .alert-warning, .alert-danger). The following example demonstrates
this:
<div
<div
<div
<div
class="alert
class="alert
class="alert
class="alert
Dismissal Alerts
To build a dismissal alert:
Add an basic alert by creating a wrapper <div> and adding a class of .alert and one of the four contextual
classes (e.g., .alert-success, .alert-info, .alert-warning, .alert-danger)
Also add optional .alert-dismissable to the above <div> class.
Add a close button.
TUTORIALS POINT
Simply Easy Learning
Links in Alerts
To get links in alerts:
Add an basic alert by creating a wrapper <div> and adding a class of .alert and one of the four contextual
classes (e.g., .alert-success, .alert-info, .alert-warning, .alert-danger)
Use the .alert-link utility class to quickly provide matching colored links within any alert.
<div class="alert alert-success">
<a href="#" class="alert-link">Success! Well done its submitted.</a>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
28
Bootstrap Progress Bars
his chapter discusses about Bootstrap progress bars. The purpose of progress bars is to show that assets
are loading, in progress, or that there is action taking place regarding elements on the page.
Progress bars use CSS3 transitions and animations to achieve some of their effects. These features are not
supported in Internet Explorer 9 and below or older versions of Firefox. Opera 12 does not support animations.
TUTORIALS POINT
Simply Easy Learning
Add a style attribute with the width expressed as a percentage. Say for example, style="60%"; indicates that
the progress bar was at 60%.
Let us see an example below:
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar"
aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
style="width: 90%;">
<span class="sr-only">90% Complete (Sucess)</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar"
aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
style="width: 30%;">
<span class="sr-only">30% Complete (info)</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-warning" role="progressbar"
aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
style="width: 20%;">
<span class="sr-only">20%Complete (warning)</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"
aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
style="width: 10%;">
<span class="sr-only">10% Complete (danger)</span>
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
29
Bootstrap Media Object
his chapter discusses about Media object. These are abstract object styles for building various types of
components (like blog comments, Tweets, etc) that feature a left- or right-aligned image alongside textual content.
The goal of the media object is to make the code for developing these blocks of information drastically shorter.
The goal of media objects (light markup, easy extendability) is achieved by applying classes to some simple
markup. There are two forms to the media object:
.media: This class allows to float a media object (images, video, audio) to the left or right of a content block.
.media-list: If you are preparing a list where the items will be part of an unordered list, use class. Useful for
comment threads or articles lists.
Let us see an example below of default media object:
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="/bootstrap/images/64.jpg"
alt="Media Object">
</a>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
This is some sample text. This is some sample text.
This is some sample text. This is some sample text.
This is some sample text. This is some sample text.
This is some sample text. This is some sample text.
</div>
</div>
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="/bootstrap/images/64.jpg"
alt="Media Object">
</a>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
This is some sample text. This is some sample text.
This is some sample text. This is some sample text.
This is some sample text. This is some sample text.
This is some sample text. This is some sample text.
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="/bootstrap/images/64.jpg"
alt="Media Object">
TUTORIALS POINT
Simply Easy Learning
</a>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
This is some sample text. This is some sample
This is some sample text. This is some sample
This is some sample text. This is some sample
This is some sample text. This is some sample
</div>
</div>
</div>
</div>
text.
text.
text.
text.
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
30
Bootstrap List Group
n this article we will study about list group. Purpose of list group component is to render complex and
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
</a>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
31
Bootstrap Panels
his chapter will discuss about Bootstrap panels. Panel component are used when you want to put your
DOM component in a box. To get a basic panel, just add class .panel to the <div> element. Also add class .paneldefault to this element as shown in the following example:
<div class="panel panel-default">
<div class="panel-body">
This is a Basic panel
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
</div>
<div class="panel-body">
Panel content
</div>
</div>
Panel footers do not inherit colors and borders when using contextual variations as they are not meant to be in the
foreground.
TUTORIALS POINT
Simply Easy Learning
<div class="panel-body">
This is a Basic panel
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
This is a Basic panel
</div>
</div>
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
This is a Basic panel
</div>
</div>
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
This is a Basic panel
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
<li
<li
<li
<li
</ul>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
32
Bootstrap Wells
well is a container <div> that causes the content to appear sunken or an inset effect on the page. To
create a well, simply wrap the content that you would like to appear in the well with a <div> containing the class
of .well. The following example shows a default well:
<div class="well">Hi, am in well !!</div>
Sizing
You can change the size of well using the optional classes well-lg or well-lg. These classes are used in
conjunction with .well class. These affect the padding, making the well larger or smaller depending on the class.
<div class="well well-lg">Hi, am in large well !!</div>
<div class="well well-sm">Hi, am in small well !!</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
33
Bootstrap Plugins Overview
he components discussed in the previous chapters under Layout Components are just the beginning.
Bootstrap comes bundled with 12 jQuery plugins that extend the features and can add more interaction to your
site. To get started with Bootstraps JavaScript plugins, you dont need to be an advanced JavaScript developer.
By utilizing Bootstrap Data API, most of the plugins can be triggered without writing a single line of code.
Bootstrap Plugins can be included on your site in two forms:
Individually: Using Bootstrap's individual *.js files. Some plugins and CSS components depend on other
plugins. If you include plugins individually, make sure to check for these dependencies in the docs.
Or compiled (all at once): Using bootstrap.js or the minified bootstrap.min.js.
Do not attempt to include both, as both bootstrap.js and bootstrap.min.js contain all plugins in a single file.
All plugins depend on jQuery. So jQuery must be included before the plugin files. Check bower.jsonto
see which versions of jQuery are supported.
Data Attributes
All of the Bootstrap plugins are accessible using the included Data API. Hence, you dont need to include a
single line of JavaScript to invoke any of the plugin features.
In some situations it may be desirable to turn this functionality of Data API off. If you need to turn off the Data
API, you can unbind the attributes by adding the following line of JavaScript:
$(document).off('.data-api')
To turn off a specific/single plugin, just include the plugin's name as a namespace along with the data-api
namespace like this:
$(document).off('.alert.data-api')
Programmatic API
The developers of Bootstrap believe that you should be able to use all of the plugins purely through the JavaScript
API. All public APIs are single, chainable methods, and return the collection acted upon say for example:
$(".btn.danger").button("toggle").addClass("fat")
TUTORIALS POINT
Simply Easy Learning
All methods accept an optional options object, a string which targets a particular method, or nothing (which initiates
a plugin with default behavior) as shown below:
// initialized with defaults
$("#myModal").modal()
// initialized with no keyboard
$("#myModal").modal({ keyboard: false })
// initializes and invokes show immediately
$("#myModal").modal('show')
Each plugin also exposes its raw constructor on a Constructor property: $.fn.popover.Constructor. If you'd like to
get a particular plugin instance, retrieve it directly from an element:
$('[rel=popover]').data('popover').
No Conflict
Bootstrap plugins can sometimes be used with other UI frameworks. In these circumstances, namespace collisions
can occasionally occur. To overcome this call .noConflict on the plugin you wish to revert the value of.
// return $.fn.button to previously assigned value
var bootstrapButton = $.fn.button.noConflict()
// give $().bootstrapBtn the Bootstrap functionality
$.fn.bootstrapBtn = bootstrapButton
Events
Bootstrap provides custom events for most plugin's unique actions. Generally, these events come in two forms:
Infinitive form: This is triggered at the start of an event. ex: show. Infinitive events
providepreventDefault functionality. This provides the ability to stop the execution of an action before it starts.
})
TUTORIALS POINT
Simply Easy Learning
CHAPTER
34
Bootstrap Transition Plugin
If you want to include this plugin functionality individually, then you will need transition.js once alongside the other
JS files. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the
minified bootstrap.min.js.
Transition.js is a basic helper for transitionEnd events as well as a CSS transition emulator. It's used by the other
plugins to check for CSS transition support and to catch hanging transitions.
Use cases
A few examples of the transition plugin:
Sliding or fading in modals. You can find an example in the chapter Bootstrap Modal Plugin.
Fading out tabs. You can find an example in the chapter Bootstrap Tab Plugin.
Fading out alerts. You can find an example in the chapter Bootstrap Alerts.
Sliding carousel panes. You can find an example in the chapter Bootstrap Carousel Plugin.
TUTORIALS POINT
Simply Easy Learning
CHAPTER
35
Bootstrap Modal Plugin
model is a child window that is layered over its parent window. Typically, the purpose is to display
content from a separate source that can have some interaction without leaving the parent window. Child windows
can provide information, interaction, or more.
If you want to include this plugin functionality individually, then you will need modal.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
You can toggle the modal plugin's hidden content:
Via data attributes: Set attribute data-toggle="modal" on a controller element, like a button or link, along
with a data-target="#identifier" or href="#identifier" to target a specific modal (with the id="identifier") to
toggle.
Via JavaScript: Using this technique you can call a modal with id="identifier" with a single line of JavaScript:
$('#identifier').modal(options)
EXAMPLE
A static modal window example is as shown in the following example:
<h2>Example of creating Modals with Twitter Bootstrap</h2>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal"
data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
This Modal title
TUTORIALS POINT
Simply Easy Learning
</h4>
</div>
<div class="modal-body">
Add some text here
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
</button>
<button type="button" class="btn btn-primary">
Submit changes
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
Details of the preceding code:
To invoke the modal window, you need to have some kind of a trigger. You can use a button or a link. Here we
have used button.
If you look in the code above, you will see that in the <button> tag, the data-target="#myModal"is the target
of the modal that you want to load on the page. This code allows you to create multiple modals on the page
and then have different triggers for each of them. Now, to be clear, you dont load multiple modals at the same
time, but you can create many on the page to be loaded at different times.
There are two classes to take note of in the modal:
o
o
The first is .modal, which is simply identifying the content of the <div> as a modal.
And second is the .fade class. When the modal is toggled, it will cause the content to fade in and out.
aria-labelledby="myModalLabel", attribute reference the modal title.
The attribute aria-hidden="true" is used to keep the Modal Window invisible till a trigger comes (like a click
on the associated button).
<div class="modal-header">, modal-header is the class to define style for the header of the modal window.
class="close", is a CSS class close that sets style for the Close button of the modal window.
data-dismiss="modal", is a custom HTML5 data attribute. Here it is used to close the modal window.
class="modal-body", is a CSS class of Bootstrap CSS to set style for body of the modal window.
class="modal-footer", is a CSS class of Bootstrap CSS to set style for footer of the modal window.
data-toggle="modal", HTML5 custom data attribute data-toggle is used to open the modal window.
Options
There are certain options which can be passed via data attributes or JavaScript to customize the look and feel of
the Modal Window. Following table lists the options:
TUTORIALS POINT
Simply Easy Learning
Option
Name
Type/Default
Value
Data
attribute
name
Description
backdrop
boolean or the
string 'static'
Default: true
databackdrop
specify static for a backdrop, if you dont want the modal to be closed
when the user clicks outside of the modal.
keyboard
boolean
Default: true
datakeyboard
Closes the modal when escape key is pressed; set to false to disable.
show
boolean
Default: true
data-show
remote
path
Default: false
data-remote
Using the jQuery .load method, inject content into the modal body. If
an href with a valid URL is added, it will load that content. An example
of this is shown below:
<a data-toggle="modal" href="remote.html" datatarget="#modal">Click me</a>
METHODS
The following are some useful methods which can be used with modal().
Method
Description
Example
Options:.modal(options)
$('#identifier').modal({
keyboard: false
})
Toggle:.modal('toggle')
$('#identifier').modal('toggle')
Show:.modal('show')
$('#identifier').modal('show')
Hide:.modal('hide')
$('#identifier').modal('hide')
EXAMPLE
The following example demonstrates the usage of methods:
<h2>Example of using methods of Modal Plugin</h2>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
TUTORIALS POINT
Simply Easy Learning
</button>
<h4 class="modal-title" id="myModalLabel">
This Modal title
</h4>
</div>
<div class="modal-body">
Press ESC button to exit.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
</button>
<button type="button" class="btn btn-primary">
Submit changes
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$(function () { $('#myModal').modal({
keyboard: true
})});
</script>
Just click the Esc button and the modal window exits.
Events
Following table lists the events to work with modal. These events may be used to hook into the function.
Event
Description
Example
show.bs.modal
$('#identifier').on('show.bs.modal',
function () {
// do something
})
shown.bs.modal
$('#identifier').on('shown.bs.modal',
function () {
// do something
})
hide.bs.modal
$('#identifier').on('hide.bs.modal',
function () {
TUTORIALS POINT
Simply Easy Learning
// do something
})
$('#identifier').on('hidden.bs.modal',
function () {
// do something
})
EXAMPLE
The following example demonstrates the usage of events:
<h2>Example of using events of Modal Plugin</h2>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
</button>
<h4 class="modal-title" id="myModalLabel">
This Modal title
</h4>
</div>
<div class="modal-body">
Click on close button to check Event functionality.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary">
Submit changes
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$(function () { $('#myModal').modal('hide')})});
</script>
<script>
$(function () { $('#myModal').on('hide.bs.modal', function () {
alert('Hey, I heard you like modals...');})
});
</script>
TUTORIALS POINT
Simply Easy Learning
As seen in the above screen, if you click on the Close button i.e hide event, an alert message is displayed.
TUTORIALS POINT
Simply Easy Learning
CHAPTER
36
Bootstrap Dropdown Plugin
he chapter Bootstrap Dropdowns covered the dropdown menu, but the interaction part was not covered
which will be explained here. Using Dropdown plugin you can add dropdowns menus to any components like
navbars, tabs, pills and buttons.
If you want to include this plugin functionality individually, then you will need dropdown.js. Else, as mentioned in
the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
You can toggle the dropdown plugin's hidden content:
Via data attributes: Add data-toggle="dropdown" to a link or button to toggle a dropdown as shown below:
<div class="dropdown">
<a data-toggle="dropdown" href="#">Dropdown trigger</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
...
</ul>
</div>
If you need to keep links intact (which is useful if the browser is not enabling JavaScript), use thedatatarget attribute instead of href="#":
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" data-target="#"
href="/page.html">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
...
</ul>
</div>
Via JavaScript: To call the dropdown toggle via JavaScript, use the following method:
$('.dropdown-toggle').dropdown()
TUTORIALS POINT
Simply Easy Learning
EXAMPLE
W ITHIN NAVBAR
The following example demonstrates usage of dropdown menu within a navbar:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</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="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
</nav>
W ITHIN TABS
The following example demonstrates usage of dropdown menu within tabs:
<p>Tabs With Dropdown Example</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>
TUTORIALS POINT
Simply Easy Learning
<li><a href="#">PHP</a></li>
</ul>
Options
There are no options.
Methods
The dropdown toggle has a simple method to show or hide the dropdown.
$().dropdown('toggle')
EXAMPLE
The following example demonstrates use of dropdown plugin method.
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<div id="myexample">
<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">Java <b
class="caret"></b></a>
<ul class="dropdown-menu">
<li><a id="action-1" 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="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
</nav>
TUTORIALS POINT
Simply Easy Learning
</div>
<script>
$(function(){
$(".dropdown-toggle").dropdown('toggle');
});
</script>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
37
Bootstrap Scrollspy Plugin
he Scrollspy (auto updating nav) plugin allows you to target sections of the page based on scroll position.
In its basic implementation, as you scroll, you can add .active classes to the navbar based on the scroll position.
If you want to include this plugin functionality individually, then you will need scrollspy.js. Else, as mentioned in
the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
You can add scrollspy behavior to your topbar navigation:
Via data attributes: add data-spy="scroll" to the element you want to spy on (typically the body). Then add
attribute data-target with the ID or class of the parent element of any Bootstrap .navcomponent. For this to
work, you must have elements in the body of the page that have matching IDs of the links that you are spying
on.
EXAMPLE
The following example shows the use of scrollspy plugin via data attributes:
<nav id="navbar-example" class="navbar navbar-default navbar-static"
role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".bs-js-navbar-scrollspy">
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
</div>
Options
Options can be passed via data attributes or JavaScript. Following table lists the options:
Option
Name
Type/Default
Value
Data attribute
name
Description
Offset
number
Default: 10
data-offset
Methods
.scrollspy('refresh'): When calling the scrollspy via the JavaScript method, you need to call the .refreshmethod to
update the DOM. This is helpful if any elements of the DOM have changed i.e if you have added or removed some
elements. Following would be the syntax to use this method.
$('[data-spy="scroll"]').each(function () {
var $spy = $(this).scrollspy('refresh')
})
EXAMPLE
Following example demonstrates the use of.scrollspy('refresh') method:
<nav id="myScrollspy" class="navbar navbar-default navbar-static"
role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".bs-js-navbar-scrollspy">
<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="#">Tutorial Name</a>
</div>
<div class="collapse navbar-collapse bs-js-navbar-scrollspy">
<ul class="nav navbar-nav">
<li class="active"><a href="#ios">iOS</a></li>
<li><a href="#svn">SVN</a></li>
<li class="dropdown">
<a href="#" id="navbarDrop1" class="dropdown-toggle"
data-toggle="dropdown">Java
TUTORIALS POINT
Simply Easy Learning
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu"
aria-labelledby="navbarDrop1">
<li><a href="#jmeter" tabindex="-1">jmeter</a></li>
<li><a href="#ejb" tabindex="-1">ejb</a></li>
<li class="divider"></li>
<li><a href="#spring" tabindex="-1">spring</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<div data-spy="scroll" data-target="#myScrollspy" data-offset="0"
style="height:200px;overflow:auto; position: relative;">
<div class="section">
<h4 id="ios">iOS<small><a href="#" onclick="removeSection(this);">
× Remove this section</a></small>
</h4>
<p>iOS is a mobile operating system developed and distributed by
Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and
Apple TV. iOS is derived from OS X, with which it shares the Darwin
foundation. iOS is Apple's mobile version of the OS X operating system
used on Apple computers.</p>
</div>
<div class="section">
<h4 id="svn">SVN<small></small></h4>
<p>Apache Subversion which is often abbreviated as SVN, is a software
versioning and revision control system distributed under an open source
license. Subversion was created by CollabNet Inc. in 2000, but
now it is developed as a project of the Apache Software Foundation,
and as such is part of a rich community of developers and users.</p>
</div>
<div class="section">
<h4 id="jmeter">jMeter<small><a href="#" onclick="removeSection(this);">
× Remove this section</a></small>
</h4>
<p>jMeter is an Open Source testing software. It is 100% pure Java
application for load and performance testing.</p>
</div>
<div class="section">
<h4 id="ejb">EJB</h4>
<p>Enterprise Java Beans (EJB) is a development architecture for
building highly scalable and robust enterprise level applications
to be deployed on J2EE compliant Application Server such as
JBOSS, Web Logic etc.</p>
</div>
<div class="section">
<h4 id="spring">Spring</h4>
<p>Spring framework is an open source Java platform that provides
comprehensive infrastructure support for developing robust Java
applications very easily and very rapidly.</p>
<p>Spring framework was initially written by Rod Johnson and was first
released under the Apache 2.0 license in June 2003.</p>
</div>
</div>
<script type="text/javascript">
$(function(){
removeSection = function(e) {
$(e).parents(".section").remove();
$('[data-spy="scroll"]').each(function () {
TUTORIALS POINT
Simply Easy Learning
Events
Following table lists the events to work with scrollspy. This event may be used to hook into the function.
Event
Description
Example
activate.bs.scrollspy
$('#myScrollspy').on('activate.bs.scrollspy',
function () {
// do something
})
EXAMPLE
Following example demonstrates the use ofactivate.bs.scrollspy event:
<nav id="myScrollspy" class="navbar navbar-default navbar-static"
role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".bs-js-navbar-scrollspy">
<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="#">Tutorial Name</a>
</div>
<div class="collapse navbar-collapse bs-js-navbar-scrollspy">
<ul class="nav navbar-nav">
<li class="active"><a href="#ios">iOS</a></li>
<li><a href="#svn">SVN</a></li>
<li class="dropdown">
<a href="#" id="navbarDrop1" class="dropdown-toggle"
data-toggle="dropdown">
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
$('[data-spy="scroll"]').each(function () {
var $spy = $(this).scrollspy('refresh')
});
}
$("#myScrollspy").scrollspy();
$('#myScrollspy').on('activate.bs.scrollspy', function () {
var currentItem = $(".nav li.active > a").text();
$("#activeitem").html("Currently you are viewing - " + currentItem);
})
});
</script>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
38
Bootstrap Tab Plugin
abs were introduced in the chapter Bootstrap Navigation Elements. By combining a few data attributes,
you can easily create a tabbed interface. With this plugin you can transition through panes of local content in tabs
or pills, even via dropdown menus.
If you want to include this plugin functionality individually, then you will need tab.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
You can enable tabbable tabs in the following two ways:
Via data attributes: you need to add data-toggle="tab" or data-toggle="pill" to the anchors.
Adding the nav and nav-tabs classes to the tab ul will apply the Bootstrap tab styling, while adding
thenav and nav-pills classes will apply pill styling.
<ul class="nav nav-tabs">
<li><a href="#identifier" data-toggle="tab">Home</a></li>
...
</ul>
Via JavaScript: you can enable tabs using Javscript as below :
$('#myTab a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
Heres an example of different ways to activate individual tabs:
// Select tab by name
$('#myTab a[href="#profile"]').tab('show')
// Select first tab
$('#myTab a:first').tab('show')
// Select last tab
$('#myTab a:last').tab('show')
// Select third tab (0-indexed)
TUTORIALS POINT
Simply Easy Learning
FADE EFFECT
To get a fade effect for tabs, add .fade to each .tab-pane. The first tab pane must also have .in to properly fade in
initial content:
<div class="tab-content">
<div class="tab-pane fade in active" id="home">...</div>
<div class="tab-pane fade" id="svn">...</div>
<div class="tab-pane fade" id="ios">...</div>
<div class="tab-pane fade" id="java">...</div>
</div>
EXAMPLE
An example of tab plugin using data attributes and fade effect is as shown in the following example:
<ul id="myTab" class="nav nav-tabs">
<li class="active">
<a href="#home" data-toggle="tab">
Tutorial Point Home
</a>
</li>
<li><a href="#ios" data-toggle="tab">iOS</a></li>
<li class="dropdown">
<a href="#" id="myTabDrop1" class="dropdown-toggle"
data-toggle="dropdown">Java
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1">
<li><a href="#jmeter" tabindex="-1" data-toggle="tab">jmeter</a></li>
<li><a href="#ejb" tabindex="-1" data-toggle="tab">ejb</a></li>
</ul>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
<p>Tutorials Point is a place for beginners in all technical areas.
This website covers most of the latest technoligies and explains
each of the technology with simple examples. You also have a
<b>tryit</b> editor, wherein you can edit your code and
try out different possibilities of the examples.</p>
</div>
<div class="tab-pane fade" id="ios">
<p>iOS is a mobile operating system developed and distributed by Apple
Inc. Originally released in 2007 for the iPhone, iPod Touch, and
Apple TV. iOS is derived from OS X, with which it shares the
Darwin foundation. iOS is Apple's mobile version of the
OS X operating system used on Apple computers.</p>
</div>
<div class="tab-pane fade" id="jmeter">
<p>jMeter is an Open Source testing software. It is 100% pure
Java application for load and performance testing.</p>
</div>
<div class="tab-pane fade" id="ejb">
<p>Enterprise Java Beans (EJB) is a development architecture
for building highly scalable and robust enterprise level
applications to be deployed on J2EE compliant
TUTORIALS POINT
Simply Easy Learning
Methods
.$().tab: This method activates a tab element and content container. Tab should have either a data-target or
an href targeting a container node in the DOM.
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a href="#identifier" data-toggle="tab">Home</a></li>
.....
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">...</div>
.....
</div>
<script>
$(function () {
$('#myTab a:last').tab('show')
})
</script>
EXAMPLE
The following example shows use of tab plugin method .tab. Here in the example the second tab iOSis activated:
<ul id="myTab" class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">
Tutorial Point Home</a>
</li>
<li><a href="#ios" data-toggle="tab">iOS</a></li>
<li class="dropdown">
<a href="#" id="myTabDrop1" class="dropdown-toggle"
data-toggle="dropdown">Java <b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1">
<li><a href="#jmeter" tabindex="-1" data-toggle="tab">
jmeter</a>
</li>
<li><a href="#ejb" tabindex="-1" data-toggle="tab">
ejb</a>
</li>
</ul>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
<p>Tutorials Point is a place for beginners in all technical areas.
TUTORIALS POINT
Simply Easy Learning
Events
Following table lists the events to work with tab plugin. This event may be used to hook into the function.
Event
Description
Example
show.bs.tab
$('a[datatoggle="tab"]').on('show.bs.tab',
function (e) {
e.target // activated tab
e.relatedTarget // previous tab
})
shown.bs.tab
$('a[datatoggle="tab"]').on('shown.bs.tab',
function (e) {
e.target // activated tab
e.relatedTarget // previous tab
TUTORIALS POINT
Simply Easy Learning
})
EXAMPLE
The following example shows use of tab plugin events. Here in the example we will display the current and
previous visited tabs:
<hr>
<p class="active-tab"><strong>Active Tab</strong>: <span></span></p>
<p class="previous-tab"><strong>Previous Tab</strong>: <span></span></p>
<hr>
<ul id="myTab" class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">
Tutorial Point Home</a></li>
<li><a href="#ios" data-toggle="tab">iOS</a></li>
<li class="dropdown">
<a href="#" id="myTabDrop1" class="dropdown-toggle"
data-toggle="dropdown">
Java <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1">
<li><a href="#jmeter" tabindex="-1" data-toggle="tab">jmeter</a></li>
<li><a href="#ejb" tabindex="-1" data-toggle="tab">ejb</a></li>
</ul>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
<p>Tutorials Point is a place for beginners in all technical areas.
This website covers most of the latest technoligies and explains
each of the technology with simple examples. You also have a
<b>tryit</b> editor, wherein you can edit your code and
try out different possibilities of the examples.</p>
</div>
<div class="tab-pane fade" id="ios">
<p>iOS is a mobile operating system developed and distributed by Apple
Inc. Originally released in 2007 for the iPhone, iPod Touch, and
Apple TV. iOS is derived from OS X, with which it shares the
Darwin foundation. iOS is Apple's mobile version of the
OS X operating system used on Apple computers.</p>
</div>
<div class="tab-pane fade" id="jmeter">
<p>jMeter is an Open Source testing software. It is 100% pure
Java application for load and performance testing.</p>
</div>
<div class="tab-pane fade" id="ejb">
<p>Enterprise Java Beans (EJB) is a development architecture
for building highly scalable and robust enterprise level
applications to be deployed on J2EE compliant
Application Server such as JBOSS, Web Logic etc.
</p>
</div>
</div>
<script>
$(function(){
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
// Get the name of active tab
var activeTab = $(e.target).text();
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
39
Bootstrap Tooltip Plugin
ooltips are useful when you need to describe a link. The plugin was inspired by jQuery.tipsy plugin written
by Jason Frame. Tooltips have since been updated to work without images, animate with a CSS animation, and
data-attributes for local title storage.
If you want to include this plugin functionality individually, then you will need tooltip.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger
element. You can add tooltips in the following two ways:
Via data attributes: To add a tooltip, add data-toggle="tooltip" to an anchor tag. The title of the anchor will
be the text of a tooltip. By default, tooltip is set to top by the plugin.
<a href="#" data-toggle="tooltip" title="Example tooltip">Hover over me</a>
Via JavaScript: Trigger the tooltip via JavaScript:
$('#identifier').tooltip(options)
Tooltip plugin is NOT only-css plugins like dropdown or other plugins discussed in previous chapters. To use this
plugin you MUST activate it using jquery (read javascript). To enable all the tooltips on your page just use this
script:
$(function () { $("[data-toggle='tooltip']").tooltip(); });
EXAMPLE
The following example demonstrates the use of tooltip plugin via data attributes.
<h4>Tooltip examples for anchors</h4>
This is a <a href="#" class="tooltip-test" data-toggle="tooltip"
title="Tooltip on left">
Default Tooltip
</a>.
This is a <a href="#" class="tooltip-test" data-toggle="tooltip"
data-placement="left" title="Tooltip on left">
Tooltip on Left
</a>.
TUTORIALS POINT
Simply Easy Learning
Options
There are certain options which can be added via the Bootstrap Data API or invoked via JavaScript. Following
table lists the options:
Option
Name
Type/Default
Value
TUTORIALS POINT
Simply Easy Learning
Data
attribute
name
Description
animation
boolean
Default: true
dataanimation
Html
boolean
Default: false
data-html
Inserts HTML into the tooltip. If false, jQuerys text method will be
used to insert content into the dom. Use text if youre worried about
XSS attacks.
placement
string|function
Default: top
dataplacement
selector
string
Default: false
data-selector
Title
string | function
Default: "
data-title
The title option is the default title value if the title attribute isnt
present.
Trigger
string
Default: 'hover
focus'
data-trigger
content
string | function
Default: ''
data-content
Delay
container
number | object
Default: 0
data-delay
string | false
Default: false
datacontainer
Methods
The following are some useful methods for tooltips:
Method
Description
Example
Options:.tooltip(options)
$().tooltip(options)
Toggle:.tooltip('toggle')
$('#element').tooltip('toggle')
Show:.tooltip('show')
$('#element').tooltip('show')
Hide: .tooltip('hide')
$('#element').tooltip('hide')
Destroy:.tooltip('destroy')
$('#element').tooltip('destroy')
TUTORIALS POINT
Simply Easy Learning
EXAMPLE
The following example demonstrates the use of tooltip plugin via data attributes.
<div style="padding: 100px 100px 10px;">
This is a <a href="#" class="tooltip-show" data-toggle="tooltip"
title="show">Tooltip on method show
</a>.
This is a <a href="#" class="tooltip-hide" data-toggle="tooltip"
data-placement="left" title="hide">Tooltip on method hide
</a>.
This is a <a href="#" class="tooltip-destroy" data-toggle="tooltip"
data-placement="top" title="destroy">Tooltip on method destroy
</a>.
This is a <a href="#" class="tooltip-toggle" data-toggle="tooltip"
data-placement="bottom" title="toggle">Tooltip on method toggle
</a>.
<br><br><br><br><br><br>
<p class="tooltip-options" >
This is a <a href="#" data-toggle="tooltip" title="<h2>'am Header2
</h2>">Tooltip on method options
</a>.
</p>
<script>
$(function
$(function
$(function
$(function
$(function
});
</script>
<div>
()
()
()
()
()
{
{
{
{
{
$('.tooltip-show').tooltip('show');});
$('.tooltip-hide').tooltip('hide');});
$('.tooltip-destroy').tooltip('destroy');});
$('.tooltip-toggle').tooltip('toggle');});
$(".tooltip-options a").tooltip({html : true });
Events
Following table lists the events to work with tooltip plugin. This event may be used to hook into the function.
Event
Description
Example
show.bs.tooltip
$('#myTooltip').on('show.bs.tooltip',
function () {
// do something
TUTORIALS POINT
Simply Easy Learning
})
shown.bs.tooltip
$('#myTooltip').on('shown.bs.tooltip',
function () {
// do something
})
hide.bs.tooltip
$('#myTooltip').on('hide.bs.tooltip',
function () {
// do something
})
hidden.bs.tooltip
$('#myTooltip').on('hidden.bs.tooltip',
function () {
// do something
})
EXAMPLE
The following example demonstrates the use of tooltip plugin via data attributes.
<h4>Tooltip examples for anchors</h4>
This is a <a href="#" class="tooltip-show" data-toggle="tooltip"
title="Default Tooltip">Default Tooltip
</a>.
<script>
$(function () { $('.tooltip-show').tooltip('show');});
$(function () { $('.tooltip-show').on('show.bs.tooltip', function () {
alert("Alert message on show");
})});
</script>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
40
Bootstrap Popover Plugin
he popover is similar to tooltip, offering an extended view complete with a heading. For the popover to
activate, a user just needs to hover the cursor over the element. The content of the popover can be populated
entirely using the Bootstrap Data API. This method requires a tooltip.
If you want to include this plugin functionality individually, then you will need popover.js and it has a dependency
of tooltip plugin. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the
minified bootstrap.min.js.
Usage
The popover plugin generates content and markup on demand, and by default places popover after their trigger
element. You can add popover in the following two ways:
Via data attributes: To add a popover, add data-toggle="popover" to an anchor/button tag. The title of the
anchor will be the text of a popover. By default, popover is set to top by the plugin.
EXAMPLE
The following example demonstrates the use of popover plugin via data attributes.
<div class="container" style="padding: 100px 50px 10px;" >
<button type="button" class="btn btn-default" title="Popover title"
data-container="body" data-toggle="popover" data-placement="left"
data-content="Some content in Popover on left">
Popover on left
TUTORIALS POINT
Simply Easy Learning
</button>
<button type="button" class="btn btn-primary" title="Popover title"
data-container="body" data-toggle="popover" data-placement="top"
data-content="Some content in Popover on top">
Popover on top
</button>
<button type="button" class="btn btn-success" title="Popover title"
data-container="body" data-toggle="popover" data-placement="bottom"
data-content="Some content in Popover on bottom">
Popover on bottom
</button>
<button type="button" class="btn btn-warning" title="Popover title"
data-container="body" data-toggle="popover" data-placement="right"
data-content="Some content in Popover on right">
Popover on right
</button>
</div>
<script>$(function ()
{ $("[data-toggle='popover']").popover();
});
</script>
</div>
Options
There are certain options which can be added via the Bootstrap Data API or invoked via JavaScript. Following
table lists the options:
Option
Name
Type/Default
Value
Data
attribute
name
Description
animation
boolean
Default: true
dataanimation
html
boolean
Default: false
data-html
Inserts HTML into the popover. If false, jQuerys text method will
be used to insert content into the dom. Use text if youre worried
about XSS attacks.
placement
string|function
Default: top
dataplacement
selector
string
Default: false
data-selector
title
string | function
data-title
The title option is the default title value if the title attribute isnt
TUTORIALS POINT
Simply Easy Learning
Default: "
trigger
delay
container
string
Default: 'hover
focus'
present.
data-trigger
number | object
Default: 0
data-delay
string | false
Default: false
datacontainer
Methods
The following are some useful methods for popover:
Method
Description
Example
Options:.popover(options)
$().popover(options)
Toggle:.popover('toggle')
$('#element').popover('toggle')
Show:.popover('show')
$('#element').popover('show')
Hide:.popover('hide')
$('#element').popover('hide')
Destroy:.popover('destroy')
$('#element').popover('destroy')
EXAMPLE
The following example demonstrates popover plugin methods:
<div class="container" style="padding: 100px 50px 10px;" >
<button type="button" class="btn btn-default popover-show"
title="Popover title" data-container="body"
data-toggle="popover" data-placement="left"
data-content="Some content in Popover with show method">
Popover on left
</button>
<button type="button" class="btn btn-primary popover-hide"
title="Popover title" data-container="body"
data-toggle="popover" data-placement="top"
data-content="Some content in Popover-hide method">
Popover on top
</button>
<button type="button" class="btn btn-success popover-destroy"
title="Popover title" data-container="body"
data-toggle="popover" data-placement="bottom"
TUTORIALS POINT
Simply Easy Learning
Events
Following table lists the events to work with popover plugin. This event may be used to hook into the function.
Event
Description
Example
show.bs.popover
$('#mypopover').on('show.bs.popover',
function () {
// do something
})
shown.bs.popover
$('#mypopover').on('shown.bs.popover',
function () {
// do something
TUTORIALS POINT
Simply Easy Learning
})
hide.bs.popover
$('#mypopover').on('hide.bs.popover',
function () {
// do something
})
hidden.bs.popover
$('#mypopover').on('hidden.bs.popover',
function () {
// do something
})
EXAMPLE
The following example demonstrates the Popover plugin events:
<div clas="container" style="padding: 100px 50px 10px;" >
<button type="button" class="btn btn-primary popover-show"
title="Popover title" data-container="body"
data-toggle="popover"
data-content="Some content in Popover with show method">
Popover on left
</button>
</div>
<script>
$(function () { $('.popover-show').popover('show');});
$(function () { $('.popover-show').on('shown.bs.popover', function () {
alert("Alert message on show");
})});
</script>
</div>
TUTORIALS POINT
Simply Easy Learning
CHAPTER
41
Bootstrap Alert Plugin
lert messages are mostly used to display information such as warning or confirmation messages to the
end users. Using alert message plugin you can add dismiss functionality to all alert messages.
If you want to include this plugin functionality individually, then you will need alert.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
You can enable dismissal of an alert in the following two ways:
Via data attributes: To dismiss via Data API just add data-dismiss="alert" to your close button to
automatically give an alert close functionality.
EXAMPLE
The following example demonstrates the use of alert plugin via data attributes.
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">
×
</a>
<strong>Warning!</strong> There was a problem with your
network connection.
</div>
TUTORIALS POINT
Simply Easy Learning
OPTIONS
No options
METHODS
The following are some useful methods for alert plugin:
Method
Description
Example
.alert()
$('#identifier').alert();
Close
Method.alert('close')
$('#identifier').alert('close');
To enable alerts to animate out when closed, make sure they have the .fade and .in class already applied to them.
EXAMPLE
The following example demonstrates use of .alert() method:
<h3>Alert messages to demonstrate alert() method </h3>
<div id="myAlert" class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Success!</strong> the result is successful.
</div>
<div id="myAlert" class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Warning!</strong> There was a problem with your
network connection.
</div>
<script type="text/javascript">
$(function(){
$(".close").click(function(){
$("#myAlert").alert();
});
});
</script>
Try this code using the Try it editor.
The following example demonstrates use of .alert('close') method:
<h3>Alert messages to demonstrate alert('close') method </h3>
<div id="myAlert" class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Success!</strong> the result is successful.
</div>
<div id="myAlert" class="alert alert-warning">
TUTORIALS POINT
Simply Easy Learning
EVENTS
Following table lists the events to work with alert plugin. This event may be used to hook into the alert function.
Event
Description
Example
close.bs.alert
$('#myalert').bind('close.bs.alert',
function () {
// do something
})
closed.bs.alert
$('#myalert').bind('closed.bs.alert',
function () {
// do something
})
EXAMPLE
The following example demonstrates the alert plugin events:
<div id="myAlert" class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Success!</strong> the result is successful.
</div>
<script type="text/javascript">
$(function(){
$("#myAlert").bind('closed.bs.alert', function () {
alert("Alert message box is closed.");
});
});
</script>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
42
Bootstrap Button Plugin
uttons were explained in chapter Bootstrap Buttons. With this plugin you can add in some interaction
such as control button states or create groups of buttons for more components like toolbars.
If you want to include this plugin functionality individually, then you will need button.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Loading State
To add a loading state to a button, simply add data-loading-text="Loading..." as an attribute to the button
element as shown in the following example:
<button id="fat-btn" class="btn btn-primary" data-loading-text="Loading..."
type="button"> Loading state
</button>
<script>
$(function() {
$(".btn").click(function(){
$(this).button('loading').delay(1000).queue(function() {
// $(this).button('reset');
});
});
});
</script>
When you click on the button the output would be as seen in the following image:
Single toggle
To activate toggling (i.e. change the normal state of a button to a push state and vice versa) on a single button,
add data-toggle="button" as an attribute to the button element as shown in the following example:
TUTORIALS POINT
Simply Easy Learning
Checkbox
You can create group of checkboxes and add toggling to it by simply adding the data attribute datatoggle="buttons" to the btn-group
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="checkbox"> Option 1
</label>
<label class="btn btn-primary">
<input type="checkbox"> Option 2
</label>
<label class="btn btn-primary">
<input type="checkbox"> Option 3
</label>
</div>
Radio
Similarly you can create group of radio inputs and add toggling to it by simply adding the data attributedatatoggle="buttons" to the btn-group.
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="options" id="option1"> Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3"> Option 3
</label>
</div>
TUTORIALS POINT
Simply Easy Learning
Usage
You can enable buttons plugin via JavaScript as below:
$('.btn').button()
Options
No options
Methods
The following are some useful methods for buttons plugin:
Method
Description
Example
button('toggle')
Toggles push state. Gives the button the appearance that it has
been activated. You can also enable auto toggling of a button by
using thedata-toggle attribute.
$().button('toggle')
.button('loading')
$().button('loading')
.button('reset')
$().button('reset')
.button(string)
$().button(string)
EXAMPLE
The following example demonstrates use of above methods:
<h2>Click on each of the buttons to see the effects of methods</h2>
<h4>Example to demonstrate .button('toggle') method</h4>
<div id="myButtons1" class="bs-example">
<button type="button" class="btn btn-primary">Primary</button>
</div>
<h4>Example to demonstrate .button('loading') method</h4>
<div id="myButtons2" class="bs-example">
<button type="button" class="btn btn-primary"
data-loading-text="Loading...">Primary
</button>
</div>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
43
Bootstrap Collapse Plugin
he collapse plugin makes it easy to make collapsing divisions of the page. Whether you use it to build
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseTwo">
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
TUTORIALS POINT
Simply Easy Learning
<div class="panel-body">
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseThree">
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
</div>
</div>
</div>
</div>
1.
2.
3.
data-toggle="collapse" is added to the link on which you click to expand or collapse the component.
href or a data-target attribute is added to the parent component, whose value is id of the child component.
data-parent attribute is added to is added for creating accordion like effect.
To create simple collapsible without the accordion markup: This can be created as in the sample
example below:
</button>
<div id="demo" class="collapse in">
</div>
As you can see in the example we have created a simple collapsible component, unlike accordion, we haven't
added the attribute data-parent.
TUTORIALS POINT
Simply Easy Learning
Usage
Following table lists the classes collapse plugin utilizes to handle the heavy lifting:
Class
Description
.collapse
.collapse.in
.collapsing
Options
There are certain options which can be passed via data attributes or JavaScript are listed in the following table:
Option
Name
Type/Default
Value
Data
attribute
name
Description
Parent
selector
Default: false
data-parent
If selector then all collapsible elements under the specified parent will
be closed when this collapsible item is shown. (similar to traditional
accordion behavior - this dependent on the accordion-group class)
Toggle
boolean
Default: true
data-toggle
Methods
The following are some methods useful to use with collapsible elements.
Method
Description
Example
Options:.collapse(options)
$('#identifier').collapse({
toggle: false
})
TUTORIALS POINT
Simply Easy Learning
Toggle:.collapse('toggle')
$('#identifier').collapse('toggle')
Show:.collapse('show')
$('#identifier').collapse('show')
Hide:.collapse('hide')
$('#identifier').collapse('hide')
EXAMPLE
The following example demonstrates the usage of methods:
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseOne">
Click me to exapand. Click me again to collapse.
Section 1--hide method
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice
lomo.
</div>
</div>
</div>
<div class="panel panel-success">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseTwo">
Click me to exapand. Click me again to collapse.
Section 2--show method
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice
lomo.
</div>
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseThree">
Click me to exapand. Click me again to collapse.
Section 3--toggle method
</a>
</h4>
TUTORIALS POINT
Simply Easy Learning
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice
lomo.
</div>
</div>
</div>
<div class="panel panel-warning">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseFour">
Click me to exapand. Click me again to collapse.
Section 4--options method
</a>
</h4>
</div>
<div id="collapseFour" class="panel-collapse collapse">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice
lomo.
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function () { $('#collapseFour').collapse({
toggle: false
})});
$(function () { $('#collapseTwo').collapse('show')});
$(function () { $('#collapseThree').collapse('toggle')});
$(function () { $('#collapseOne').collapse('hide')});
</script>
EVENTS
Following table lists few events for hooking into collapse functionality.
Event
Description
TUTORIALS POINT
Simply Easy Learning
Example
show.bs.collapse
$('#identifier').on('show.bs.collapse',
function () {
// do something
})
shown.bs.collapse
$('#identifier').on('shown.bs.collapse',
function () {
// do something
})
hide.bs.collapse
$('#identifier').on('hide.bs.collapse',
function () {
// do something
})
hidden.bs.collapse
$('#identifier').on('hidden.bs.collapse',
function () {
// do something
})
EXAMPLE
The following example demonstrates the usage of events:
<div class="panel-group" id="accordion">
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseexample">
Click me to exapand. Click me again to collapse.
Section --shown event
</a>
</h4>
</div>
<div id="collapseexample" class="panel-collapse collapse">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson
cred nesciunt sapiente ea proident.
Ad vegan excepteur butcher vice lomo.
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#collapseexample').on('show.bs.collapse', function () {
alert('Hey, this alert shows up when you expand it');})
});
</script>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
44
Bootstrap Carousel Plugin
he Bootstrap carousel is a flexible, responsive way to add a slider to your site. In addition to being
responsive, the content is flexible enough to allow images, iframes, videos, or just about any type of content that
you might want.
If you want to include this plugin functionality individually, then you will need carousel.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Example
A simple slideshow below shows a generic component for cycling through elements like a carousel, using the
Bootstrap carousel plugin. To implement the carousel, you just need to add the code with the markup. There is no
need for data attributes, just simple class-based development.
<div id="myCarousel" class="carousel slide">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<img src="/bootstrap/images/slide1.png" alt="First slide">
</div>
<div class="item">
<img src="/bootstrap/images/slide2.png" alt="Second slide">
</div>
<div class="item">
<img src="/bootstrap/images/slide3.png" alt="Third slide">
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel"
data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel"
data-slide="next">›</a>
</div>
TUTORIALS POINT
Simply Easy Learning
OPTIONAL CAPTIONS
You can add captions to your slides easily with the .carousel-caption element within any .item. Place just about
any optional HTML within there and it will be automatically aligned and formatted. Following example demonstrates
this:
<div id="myCarousel" class="carousel slide">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<img src="/bootstrap/images/slide1.png" alt="First slide">
<div class="carousel-caption">This Caption 1</div>
</div>
<div class="item">
<img src="/bootstrap/images/slide2.png" alt="Second slide">
<div class="carousel-caption">This Caption 2</div>
</div>
<div class="item">
<img src="/bootstrap/images/slide3.png" alt="Third slide">
<div class="carousel-caption">This Caption 3</div>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel"
data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel"
data-slide="next">›</a>
</div>
TUTORIALS POINT
Simply Easy Learning
Usage
Via data attributes: Use data attributes to easily control the position of the carousel.
o
o
o
Attribute data-slide accepts the keywords prev or next, which alters the slide position relative to its
current position.
Use data-slide-to to pass a raw slide index to the carousel data-slide-to="2", which shifts the slide
position to a particular index beginning with 0.
The data-ride="carousel" attribute is used to mark a carousel as animating starting at page load.
Via JavaScript: The carousel can be manually called with JavaScript as below:
$('.carousel').carousel()
Options
There are certain options which can be passed via data attributes or JavaScript are listed in the following table:
Option
Name
Type/Default
Value
Data attribute
name
Description
interval
number
Default: 5000
data-interval
pause
string
Default: "hover"
data-pause
wrap
boolean
Default: true
data-wrap
Methods
The following are some methods useful to use with carousel code.
Method
Description
Example
.carousel(options)
$('#identifier').carousel({
interval: 2000
TUTORIALS POINT
Simply Easy Learning
})
.carousel('cycle')
$('#identifier').carousel('cycle')
.carousel('pause')
$('#identifier')..carousel('pause')
.carousel(number)
$('#identifier').carousel(number)
.carousel('prev')
$('#identifier').carousel('prev')
.carousel('next')
$('#identifier').carousel('next')
EXAMPLE
The following example demonstrates the usage of methods:
<div id="myCarousel" class="carousel slide">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"
class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<img src="/bootstrap/images/slide1.png" alt="First slide">
</div>
<div class="item">
<img src="/bootstrap/images/slide2.png" alt="Second slide">
</div>
<div class="item">
<img src="/bootstrap/images/slide3.png" alt="Third slide">
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel"
data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel"
data-slide="next">›</a>
<!-- Controls buttons -->
<div style="text-align:center;">
<input type="button" class="btn start-slide" value="Start">
<input type="button" class="btn pause-slide" value="Pause">
<input type="button" class="btn prev-slide" value="Previous Slide">
<input type="button" class="btn next-slide" value="Next Slide">
<input type="button" class="btn slide-one" value="Slide 1">
<input type="button" class="btn slide-two" value="Slide 2">
<input type="button" class="btn slide-three" value="Slide 3">
</div>
</div>
TUTORIALS POINT
Simply Easy Learning
<script>
$(function(){
// Initializes the carousel
$(".start-slide").click(function(){
$("#myCarousel").carousel('cycle');
});
// Stops the carousel
$(".pause-slide").click(function(){
$("#myCarousel").carousel('pause');
});
// Cycles to the previous item
$(".prev-slide").click(function(){
$("#myCarousel").carousel('prev');
});
// Cycles to the next item
$(".next-slide").click(function(){
$("#myCarousel").carousel('next');
});
// Cycles the carousel to a particular frame
$(".slide-one").click(function(){
$("#myCarousel").carousel(0);
});
$(".slide-two").click(function(){
$("#myCarousel").carousel(1);
});
$(".slide-three").click(function(){
$("#myCarousel").carousel(2);
});
});
</script>
Events
Bootstrap's carousel class exposes two events for hooking into carousel functionality which are listed in the
following table.
Event
Description
TUTORIALS POINT
Simply Easy Learning
Example
slide.bs.carousel
$('#identifier').on('slide.bs.carousel',
function () {
// do something
})
slid.bs.carousel
$('#identifier').on('slid.bs.carousel',
function () {
// do something
})
EXAMPLE
The following example demonstrates the usage of events:
<div id="myCarousel" class="carousel slide">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"
class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<img src="/bootstrap/images/slide1.png" alt="First slide">
</div>
<div class="item">
<img src="/bootstrap/images/slide2.png" alt="Second slide">
</div>
<div class="item">
<img src="/bootstrap/images/slide3.png" alt="Third slide">
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel"
data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel"
data-slide="next">›</a>
</div>
<script>
$(function(){
$('#myCarousel').on('slide.bs.carousel', function () {
alert("This event fires immediately when the slide instance method"
+"is invoked.");
});
});
</script>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
CHAPTER
45
Bootstrap Affix Plugin
he affix plugin allows a <div> to become affixed to a location on the page. You can also toggle it's pinning
on and off using this plugin. A common example of this is social icons. They will start in a location, but as the page
hits a certain mark, the <div> will become locked in place and will stop scrolling with the rest of the page.
If you want to include this plugin functionality individually, then you will need affix.js. Else, as mentioned in the
chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.
USAGE
You can use the affix plugin via data attributes or manually with your own JavaScript as discussed below.
Via data attributes: To easily add affix behavior to any element, just add data-spy="affix" to the element you
want to spy on. Use offsets to define when to toggle the pinning of an element.
EXAMPLE
The following example demonstrates the usage through data attributes:
<div class="container">
<div class="jumbotron">
<h1>Bootstrap Affix Plugin example</h1>
</div>
<div id="myNav" data-spy="affix" data-offset-top="60"
data-offset-bottom="200">
<div class="col-md-3">
<ul class="nav nav-tabs nav-stacked affix" data-spy="affix"
data-offset-top="190">
<li class="active"><a href="#one">Tutorial One</a></li>
<li><a href="#two">Tutorial Two</a></li>
<li><a href="#three">Tutorial Three</a></li>
</ul>
</div>
<div class="col-md-9">
<h2 id="one">Tutorial One</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam eu sem tempor, varius quam at, luctus dui. Mauris magna
metus, dapibus nec turpis vel, semper malesuada ante.
Vestibulum id metus ac nisl bibendum scelerisque non non
purus. Suspendisse varius nibh non aliquet sagittis. In
tincidunt orci sit amet elementum vestibulum. Vivamus
fermentum in arcu in aliquam. Quisque aliquam porta odio
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
Via JavaScript: You can affix an element manually with JavaScript as below:
$('#myAffix').affix({
offset: {
top: 100, bottom: function () {
return (this.bottom =
$('.bs-footer').outerHeight(true))
})
EXAMPLE
The following example demonstrates the usage through data attributes:
<div class="container">
<div class="jumbotron">
<h1>Bootstrap Affix Plugin example</h1>
</div>
<div>
<div class="col-md-3">
<ul class="nav nav-tabs nav-stacked affix" id="myNav">
<li class="active"><a href="#one">Tutorial One</a></li>
<li><a href="#two">Tutorial Two</a></li>
<li><a href="#three">Tutorial Three</a></li>
</ul>
</div>
<div class="col-md-9">
<h2 id="one">Tutorial One</h2>
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
TUTORIALS POINT
Simply Easy Learning
Options
There are certain options which can be passed via data attributes or JavaScript are listed in the following table:
Option
Name
Type/Default
Value
offset
number |
function | object
Default: 10
TUTORIALS POINT
Simply Easy Learning
Data
attribute
name
Description
data-offset