Bootstrap Dropdowns
This chapter focuses on Bootstrap dropdowns. A dropdown is a toggleable contextual menu that displays links in a list format. This is achieved through interaction with the Dropdown JavaScript plugin to achieve this effect.
To use a dropdown, simply add it inside the class .dropdown to enable it. The following example demonstrates a basic dropdown:
Example
<div class="dropdown">
<button type="button" class=">btn dropdown-toggle
"
id
=
"
dropdownMenu1
"
data-toggle
=
"
dropdown
"
Topic
<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
Try it »
The result is as follows:
Option
Alignment
By passing a selector to the .dropdown-menu Add the class .pull-right to right-align the dropdown. The following example demonstrates this:
Example
<div class="dropdown">
<button type="button" class=">btn dropdown-toggle
"
id
=
"
dropdownMenu1
"
data-toggle
=
"
dropdown
"
Topic
<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
Try it »
The result is as follows:
Title
You can use the class dropdown-header to add a header to the label area of the dropdown. The following example demonstrates this:
Example
<div class="dropdown">
<button type="button" class=">btn dropdown-toggle
"
id
=
"
dropdownMenu1
"
data-toggle
=
"
dropdown
"
Topic
<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
Try it »
The result is as follows:
More examples
| class | Description | Example |
|---|---|---|
| .dropdown | To specify a dropdown, the dropdown is wrapped in .dropdown | Try it |
| .dropdown-menu | Create a Dropdown Menu | Try it |
| .dropdown-menu-right | Right-aligned Dropdown | Try it |
| .dropdown-header | Adding a Header to a Dropdown | Try it |
| .dropup | Specifying a Drop-up Menu | Try it |
| .disabled | Disabled Items in a Dropdown | Try it |
| .divider | Dividers in a Dropdown | Try it |