Home > Web Front-end > Bootstrap Tutorial > A simple introduction to drop-down menus in Bootstrap

A simple introduction to drop-down menus in Bootstrap

青灯夜游
Release: 2021-06-22 11:10:40
forward
2764 people have browsed it

This article will give you a detailed introduction to the drop-down menu in Bootstrap. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A simple introduction to drop-down menus in Bootstrap

When interacting with web pages, context menus or hidden/show menu items are often required. Bootstrap provides a switchable, contextual menu by default for displaying a link list. Moreover, the menu display in various interactive states needs to be used in conjunction with the javascript plug-in. [Related recommendations: "bootstrap Tutorial"]

How to use

When using the drop-down menu of the Bootstrap framework, you must call the drop-down menu provided by the Bootstrap framework bootstrap.js file. Of course, if you are using the uncompiled version, you can find a file named "dropdown.js" in the js folder, and you can also call this js file

Because Bootstrap's component interaction effects all depend on A plug-in written by the jQuery library, so jquery.js must be loaded before using bootstrap.js to have an effect

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
Copy after login

Basic usage

When using the Bootstrap framework When using a drop-down menu component, it is very important to use its structure correctly. If the structure and class name are not used correctly, it will directly affect whether the component can be used normally

 1. Use a container named "dropdown" Wraps the entire drop-down menu element

<div class="dropdown"></div>
Copy after login

 2. Use a

Copy after login

A simple introduction to drop-down menus in Bootstrap

【Menu Title】

You can add a title to any drop-down menu to indicate a group of actions

<li class="dropdown-header">Dropdown header</li>
Copy after login
.dropdown-header {
  display: block;
  padding: 3px 20px;
  font-size: 12px;
  line-height: 1.42857143;
  color: #999;
}
Copy after login
<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
    Dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li role="presentation" class="dropdown-header">第一部分菜单头部</li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">下拉菜单项</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">下拉菜单项</a></li>
    <li role="presentation" class="divider"></li>
    <li role="presentation" class="dropdown-header">第二部分菜单头部</li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">下拉菜单项</a></li>
  </ul>
</div>
Copy after login

A simple introduction to drop-down menus in Bootstrap

【Alignment】

The drop-down menu in the Bootstrap framework is left aligned by default. If you want the drop-down menu to be right-aligned relative to the parent container, you can add a "dropdown-menu-right" class name to "dropdown-menu"

.dropdown-menu-right {
  right: 0;
  left: auto;
}
Copy after login

Since

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template