OUTPUT:
Float to leftFloat to left
.pull-right
The .pull-right class floats an element to right.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="pull-right">Float to right</div>
<p class="pull-right">Float to right</p>
.text-muted
The .text-muted class makes an element grayed out by changing its color value.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="text-muted">This text is grayed out.</div>
<p class="text-muted">This paragraph is grayed out.</p>
Output:
This text is grayed out.
This paragraph is grayed out.
11.16 Advanced Bootstrap
11.16.1 DropdownsDropdowns within Navs Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<ul class="nav nav-pills">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Messages <b class="caret"></b></a>
</ul>
</li>
<li class="dropdown pull-right">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Admin <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Settings</a></li>
</ul>
</li>
</ul>
OUTPUT:
Bootstrap Split Button Dropdowns
The following examples will show you how to add dropdowns to split buttons.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="btn-group">
<button class="btn">Action</button>
<button data-toggle="dropdown" class="btn dropdown-toggle"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
OUTPUT:
Dropdowns Inside Button Groups Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="btn-group">
<button class="btn btn-primary" type="button">1</button>
<button class="btn btn-primary" type="button">2</button>
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-primary dropdown-toggle">Dropdown <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
</div>
OUTPUT:
Adding Dropdowns via JavaScript
You may also add dropdowns manually using the JavaScript — just call the
dropdown()Bootstrap method with the "id" or "class" selector of the link or button element in your JavaScript code.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown-toggle").dropdown();
});
</script>
Options None
Methods
This is the standard bootstrap's dropdown method:
$().dropdown('toggle')
A programmatic api for toggling menus for a given navbar or tabbed navigation.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown-toggle").dropdown('toggle');
});
</script>
Events
These are the standard Bootstrap events to enhance the dropdown functionality. All dropdown events are fired at the .dropdown-menu's parent element.
Event Description
show.bs.dropdown This event fires immediately when the show instance method is called. You can use the event.relatedTarget to target the toggling anchor element.
shown.bs.dropdown This event is fired when the dropdown has been made visible to the user. It will wait for CSS transitions, to complete. You can use theevent.relatedTarget to target the toggling anchor element.
hide.bs.dropdown This event is fired immediately when the hide instance method has been called. You can use the event.relatedTarget to target the toggling anchor element.
hidden.bs.dropdown This event is fired when the dropdown has finished being hidden from the user. It will wait for CSS transitions, to complete. You can use the event.relatedTarget to target the toggling anchor element.
The following example displays the text content of dropdown link when the users click on it.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown").on("show.bs.dropdown", function(e){
var linkText = $(e.relatedTarget).text(); // Get the link text
alert("Click on OK button to view the dropdown menu for - " + linkText);
});
});
</script>
11.16.2 Tooltips
Triggering the Tooltips
Tooltips can be triggered via JavaScript — just call the tooltip() Bootstrap method with the"id" or "class" selector of the target element in your JavaScript code.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".tooltip-examples a").tooltip();
});
</script>
<body>
<button type="button" class="btn btn-default" data-toggle="tooltip"
dataplacement="left" title="Tooltip on left">Tooltip on left</button> <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top"
title="Tooltip on top">Tooltip on top</button> <button type="button" class="btn btn-default" datatoggle="tooltip" data-placement="bottom" title="Tooltip on
bottom">Tooltip on bottom</button> <button type="button" class="btn btn-default"
data-toggle="tooltip" data-placement="right" title="Tooltip on right">Tooltip on right</button>
</body>
OUTPUT:
Note:For performance reasons, the tooltip and popover data-apis are opt in, means
to use tooltips and popovers you must initialize them yourself.
Setting the Position of Tooltips
You can set tooltips to appear on top, right, bottom and left sides of an element.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".tip-top").tooltip({placement : 'top'});
$(".tip-right").tooltip({placement : 'right'});
$(".tip-bottom").tooltip({placement : 'bottom'});
$(".tip-left").tooltip({ placement : 'left'});
});
</script>
Options
There are certain options which may be passed to tooltip() Bootstrap method to customize the functionality of the tooltip plug-in.
Name Type Default Value Description
animation boolean true Apply a CSS fade
transition to the tooltip.
html boolean false Insert html into the tooltip. If false,
jQuery'stext() method will be used to insert content into the DOM.
Use text if you're worried about XSS attacks.
placement string | 'top' Sets the position of
Name Type Default Value Description
function the tooltip — top |
bottom | left | right
| auto. When "auto"
value is specified, it will dynamically reorient the tooltip.
For example, if placement value is
"auto top", the tooltip will display on the top when possible, otherwise it will display on the bottom.
selector string false If a selector is provided,
tooltip objects will be attached to the specified targets.
title string | function
'' Sets the default title
value if title attribute isn't present.
trigger string 'hover focus' Specify how tooltip is
triggered — click | hover | focus | manual.
Note you case pass trigger mutliple, space seperated, trigger types.
delay number
| object
0 Time to delay in
showing and hiding the tooltip (ms) — does not apply to manual trigger type. If a number is supplied, delay is applied to both hide/show Object structure is: delay:
{ show: 500, hide:
100 } container string |
false
false Appends the tooltip to a
specific
elementcontainer:
'body' template string '<div class="tooltip"
role="tooltip"><div
class="tooltiparrow"></div><div class="tooltipinner"></div></div>'
Base HTML to use when creating the tooltip. The tooltip's title will be inserted into the element having the
You may also set these options for tooltips using the data attributes — just append the option name to data-, like data-animation="", data-placement="" etc.
Methods
These are the standard bootstrap's tooltip methods:
$().tooltip(options)
This method attaches the tooltip handler to a group of elements. Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){ $(".tooltip-examples a").tooltip({ title : 'It works in absence of title attribute.'
});
});
</script>
.tooltip('show')
This method reveals an element's tooltip.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".show-tooltip").click(function(){
$(".tooltip-examples a").tooltip('show');
});
});
.tooltip('hide')
This method hides an element's tooltip.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".hide-tooltip").click(function(){
$(".tooltip-examples a").tooltip('hide');
});
});
.tooltip('toggle')
This method toggles an element's tooltip.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".toggle-tooltip").click(function(){
$(".tooltip-examples a").tooltip('toggle');
});
});
tooltip('destroy')
This method hides and destroys an element's tooltip.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".destroy-tooltip").click(function(){
$(".tooltip-examples a").tooltip('destroy');
});
});
</script>
11.16.3 Popovers
Triggering the Popovers Example:
<!DOCTYPE html> <html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Bootstrap 3 Popover</title>
<link rel="stylesheet"
$('[data-toggle="popover"]').popover({
placement : 'top'
<button type="button" class="btn btn-primary" data-toggle="popover" title="Popover title" data-content="Default popover">Popover</button>
<button type="button" class="btn btn-success" data-toggle="popover" title="Popover title" data-content="Another popover">Another popover</button>
<button type="button" class="btn btn-info" data-toggle="popover" title="Popover title" data-content="A larger popover to demonstrate the max-width of the Bootstrap popover.">Large popover</button>
<button type="button" class="btn btn-warning" data-toggle="popover"
title="Popover title" data-content="The last popover!">Last popover</button> </div>
</body>
</html> OUTPUT:
Note:For performance reasons, the tooltip and popover data-apis are opt in, means to use tooltips and popovers you must initialize them yourself.
Options
There are certain options which may be passed to popover() Bootstrap method to customize the functionality of the tooltip plug-in.
Name Type Default Value Description
animation boolean true Apply a CSS fade
transition to the popover.
html boolean false Insert html into the
popover. If false, jQuery'stext() method will be used to insert content into the DOM.
Use text if you're worried about XSS attacks.
placement string | function
'right' Sets the position of
the popover — top
| bottom | left | right | auto. When
"auto" value is specified, it will dynamically reorient the popover. For example, if
placement value is
"auto left", the popover will display to the left when possible, otherwise it will display to right.
selector string false If a selector is provided,
popover objects will be attached to the
specified targets.
title string | function
'' Sets the default title
value if title attribute isn't present.
trigger string 'click' Specify how popover is
triggered — click | hover | focus | manual.
content string | function
'' Sets the default
content value if
'datacontent' attribute isn't present.
delay number
| object
0 Time to delay in
showing and hiding the popover (ms) — does not apply to manual trigger type.
If a number is supplied, delay is applied to both
You may also set these options for popover s using the data attributes — just append the option name to data-, like data-animation="", data-placement="" etc.
Methods
These are the standard bootstrap's popover methods:
$().popover(options)
This method attaches the popover handler to a group of elements. Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".popover-examples a").popover({
title : 'Default title value' });
});
popover('show')
This method reveals an element's popover.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".show-popover").click(function(){
$(".popover-examples a").popover('show');
This method hides an element's popover.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".hide-popover").click(function(){
$(".popover-examples a").popover('hide');
});
});
.popover('toggle')
This method toggles an element's popover.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".toggle-popover").click(function(){
$(".popover-examples a").popover('toggle');
});
});
.popover('destroy')
This method hides and destroys an element's popover.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
$(document).ready(function(){
$(".destroy-popover").click(function(){
$(".popover-examples a").popover('destroy');
});
});
11.16.4 Alerts
Warning Alerts Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Warning!</strong> There was a problem with your network connection.
</div>
OUTPUT:
— Similarly you can create other alert messages.
Error or Danger Alerts Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="alert alert-error">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Error!</strong> A problem has been occurred while submitting your data.
</div>
OUTPUT:
Success or Confirmation Alerts
To create success or confirmation alert messages add an extra class .alert-success to the.alert base class.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Success!</strong> Your message has been sent successfully.
</div>
OUTPUT:
Information Alerts
For information alert messages add an extra class .alert-info to the .alert base class.
Example:
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="JQuery.js"></script>
<div class="alert alert-info">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Note!</strong> Please read the comments carefully. </div>
OUTPUT:
Dismiss Alerts via JavaScript
You may also enable the dismissal of an alert via JavaScript.
Example:
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".close").click(function(){
$("#myAlert").alert();
});
});
</script>
Methods
These are the standard bootstrap's alerts methods:
$().alert()
This method wraps all alerts with close functionality.
Example:
<script type="text/javascript">
$(document).ready(function(){
$(".close").click(function(){
$(".alert").alert();
});
});
</script>
Tip: If you to want to enable transition in your alert messages box while closing, make sure you have already applied the class .fade and .in to them.
$().alert('close')
This method closes an alert message box.
Example:
<script type="text/javascript">
$(document).ready(function(){
$(".close").click(function(){
$("#myAlert").alert('close');
});
});
</script>
Example:
<script type="text/javascript">
$(document).ready(function(){
$("#myAlert").on('closed.bs.alert', function () { alert("Alert message box has been closed.");
});
});
</script>
11.16.5 Tabs
Creating Tabs with Bootstrap Example:
Creating Tabs with Bootstrap Example: