English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Bootstrap Dropdown Menu

Bootstrap plugins This chapter will focus on Bootstrap dropdown menus. Dropdown menus are toggleable context menus displayed in list format. This can be achieved by using Dropdown menu (Dropdown) JavaScript plugin

to interact with it. .dropdown If you want to use the dropdown menu, you just need to add the class

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Add a dropdown menu inside. The following example demonstrates the basic dropdown menu:/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js">/script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js">/script>
</head>
<body>
<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/Network</a>
		</li>
		<li role="presentation" class="divider"></li>
		<li role="presentation">
			<a role="menuitem" tabindex="-1" href="#">A separate link</a>
		</li>
	</ul>
</div>
</body>
</html>
Test to see ‹/›

The results are as follows:

Dropdown menu (Dropdown)<

Options

By aligning .dropdown-menu Add class .pull-right Align dropdown menu to the right. The following example demonstrates this:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Align dropdown menu to the right</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js">/script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js">/script>
</head>
<body>
<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/Network</a>
		</li>
		<li role="presentation" class="divider"></li>
		<li role="presentation">
			<a role="menuitem" tabindex="-1" href="#">A separate link</a>
		</li>
	</ul>
</div>
</body>
</html>
Test to see ‹/›

The results are as follows:

Title

You can use the class dropdown-header Add a title to the label area of the dropdown menu. The following example demonstrates this:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Dropdown menu title</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js">/script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js">/script>
</head>
<body>
<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 menu title</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/Network
			</a>
		</li>
		<li role="presentation" class="divider"></li>
		<li role="presentation" class="dropdown-header">Dropdown menu title</li>
		<li role="presentation">
			<a role="menuitem" tabindex="-1" href="#">A separate link</a>
		</li>
	</ul>
</div>
</body>
</html>
Test to see ‹/›

The results are as follows:

More Examples

ClassDescriptionExample
.dropdownSpecify the Dropdown, All Dropdowns Are Wrapped in .dropdownTry It
.dropdown-menuCreate a Dropdown MenuTry It
.dropdown-menu-rightAlign Dropdown Menu to the RightTry It
.dropdown-headerAdd a Title to Dropdown MenuTry It
.dropupSpecify Dropdowns That Pop Up UpwardTry It
.disabledDisabled Items in Dropdown MenuTry It
.dividerSeparator in Dropdown MenuTry It