Bootstrap 3.0 study notes buttons and drop-down menus

Bootstrap 3.0 study notes buttons and drop-down menus

The previous article was a simple review of the Bootstrap CSS part, and many details were overlooked. However, I went through most of the content, implemented it with code, and saw the real effect. Pretty good. Then the next few articles will mainly explain the components of Bootstrap. Then this article mainly explains the following contents

1. Drop-down menu

2. Button Group

3. Button drop-down menu

4. Summary

Let's get familiar with the code to start building a page. First, create a new test web page and add the following code


Copy code
The code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]>
<script src="<a href="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script">https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script</a>>
<script src="<a href="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script">https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script</a>>
<![endif]-->
</head>
<script src="js/jquery-2.0.3.min.js"></script> in <body>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

If you don't understand something, I have introduced it in my previous article. You can click the link to view it http://www.cnblogs.com/aehyok/p/3398359.html

Drop-down menu

A toggleable, contextual menu for displaying a list of links.

Case

Wrap the dropdown trigger and the dropdown menu in .dropdown, then add the HTML code that makes up the menu.


Copy code
The code is as follows:

<div class="dropdown">
<button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown"> Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>

From the above code, you can find that there may be many unfamiliar style classes or attributes.

A Dropdown button and a small icon caret on the right. Of course, the small icon and the button text are at the same level.

First, there is a dropdown-toggle in the button, and a data-toggle attribute. The list pops up based on this attribute.

The dropdown-menu immediately following the ul tag should be used in conjunction with the style class dropdown-toggle of the button above, and then bound to the button above through aria-labelledby.

Next, there is a divider in the fourth li tag, which is actually a dividing line style class.

This is probably how I understand it, but it is definitely not a complete understanding.

Alignment Options

Add .text-right to the drop-down menu .dropdown-menu to align the text to the right.


Copy code
The code is as follows:

<div class="dropdown">
<button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown"> Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu text-right" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>

Just add a text-right class to the ul tag in the code above.

title

In any drop-down menu you can identify a group of actions by adding a title.


Copy code
The code is as follows:

<h1>Drop-down menu</h1>
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown"> Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu text-right" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation" class="dropdown-header">Dropdown header</li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</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>

The main thing is to add <li role="presentation" class="dropdown-header">Dropdown header</li> which has a .dropdown-header style class.

Disabled menu items

Add .disabled to the <li> in the drop-down menu to disable the link.

Continue to modify the above code and replace the code in the Something else here line


Copy code
The code is as follows:
<li class="disabled" role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>

The main thing is to add the .disabled style class to the li tag.

You can check the effect after running it. In fact, the effect is similar to the title style above. When you click it, a disabled icon will be displayed. Can't capture the picture.

Button Group

Tooltips and popups in button groups require special setup

When applying tooltips or popovers to elements within a .btn-group, you must specify the container: 'body' option to avoid unwanted side effects (such as making the page element wider and/or losing its rounded corners when the tooltip or popover is triggered).

Basic Case

Put a series of .btn buttons into a .btn-group.


Copy code
The code is as follows:

<div class="btn-group">
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">Middle</button>
<button type="button" class="btn btn-default">Right</button>
</div>

Through .btn-group, you can group a group of buttons and add the style class btn to them

Button Toolbar

Combine a group of <div class="btn-group"> into a <div class="btn-toolbar"> to make a more complex component.


Copy code
The code is as follows:

<div class="btn-toolbar" role="toolbar">
<div class="btn-group">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button>
<button type="button" class="btn btn-default">3</button>
<button type="button" class="btn btn-default">4</button>
<button type="button" class="btn btn-default">5</button>
<button type="button" class="btn btn-default">6</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">7</button>
<button type="button" class="btn btn-default">8</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">9</button>
</div>
</div>

size

Just add .btn-group-* to the .btn-group instead of applying size classes to every button in the group.


Copy code
The code is as follows:

<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button>
<button type="button" class="btn btn-default">3</button>
<button type="button" class="btn btn-default">4</button>
<button type="button" class="btn btn-default">5</button>
<button type="button" class="btn btn-default">6</button>
</div>
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-default">7</button>
<button type="button" class="btn btn-default">8</button>
</div>
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-default">9</button>
</div>

Nesting

To blend a dropdown menu into a series of buttons, place a .btn-group inside another .btn-group.


Copy code
The code is as follows:

<div class="btn-group">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button></p> <p> <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</a></li>
<li><a href="#">Dropdown link</a></li>
</ul>
</div>
</div>

Vertical Arrangement

Make a group of buttons appear vertically instead of horizontally.


Copy code
The code is as follows:

<div class="btn-group btn-group-vertical">
<a href="#">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button>

</a>
<div class="btn-group">
<a href="#">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> Dropdown </button>
</a>
<ul class="dropdown-menu">
<li><a href="#">Dropdown link</a></li>
<li><a href="#">Dropdown link</a></li>
</ul>
</div>
</div>
</div>

Justified link arrangement

Makes a group of buttons stretch to the same size, fitting the width of the parent element.

Usage of specific elements

This only works on <a> elements since <button> cannot have these styles applied to them.


Copy code
The code is as follows:

<div class="btn-group btn-group-justified">
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">Middle</button>
<button type="button" class="btn btn-default">Right</button>
</div>

Button drop-down menu

You can make any button a dropdown menu trigger by putting it into a .btn-group and adding the correct menu markup.

Single button drop-down menu

By changing some basic markup, you can turn a button into a drop-down menu switch.


Copy code
The code is as follows:

<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> Action <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>

Split button drop-down menu

Similarly, a split button dropdown menu requires the same change markup, but with an additional split button.


Copy code
The code is as follows:

<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
<div class="dropdown">
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</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>


You can only click on the small icon to display the drop-down menu.

size

Drop-down menu buttons are available for buttons of all sizes.


Copy code
The code is as follows:

<div class="btn-group">
<button class="btn btn-default btn-lg dropdown-toggle" type="button" data-toggle="dropdown"> Large button <span class="caret"></span>
</button>
<ul class="dropdown-menu"> ... </ul>
</div>
<!-- Small button group -->
<div class="btn-group">
<button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown"> Small button <span class="caret"></span>
</button>
<ul class="dropdown-menu"> ... </ul>
</div>
<!-- Extra small button group -->
<div class="btn-group">
<button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown"> Extra small button <span class="caret"></span>
</button>
<ul class="dropdown-menu"> ... </ul>
</div>

Use the style classes .btn-lg, .btn-sm, and .btn-xs to control the size of the button.

Pop-up menu

Adding .dropup to a parent element will trigger the drop-down menu above the element.


Copy code
The code is as follows:

<div class="btn-group dropup">
<button type="button" class="btn btn-default">Dropup</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>

Summarize

This article mainly studies buttons and drop-down menus, and then the combination of buttons and drop-down menus. There are quite a lot of variations and the styles are good, but it is still not so convenient to start using, because the introduction here is not so detailed, and it is still a bit difficult to learn. But it doesn’t matter, just practice more and you will understand it slowly.

<<:  CSS achieves the effect of aligning multiple elements at both ends in a box

>>:  CentOS 7.6 batch add, modify and delete virtual network cards operation introduction

Recommend

Detailed explanation of this reference and custom properties in JavaScript

Table of contents 1. this keyword 2. Custom attri...

CSS3 text animation effects

Effect html <div class="sp-container"...

A Deep Dive into the MySQL InnoDB Storage Engine

Preface In MySQL, InnoDB belongs to the storage e...

How to unify the character set on an existing mysql database

Preface In the database, some data tables and dat...

Usage and difference of Js module packaging exports require import

Table of contents 1. Commonjs exports and require...

The difference between Vue interpolation expression and v-text directive

Table of contents 1. Use plugin expressions 2. Us...

10 Deadly Semantic Mistakes in Web Typography

<br />This is from the content of Web front-...

Detailed explanation of HTML table inline format

Inline format <colgroup>...</colgroup>...

Nginx memory pool source code analysis

Table of contents Memory Pool Overview 1. nginx d...

Even a novice can understand the difference between typeof and instanceof in js

Table of contents 1. typeof 2. instanceof 3. Diff...

Sample code for implementing PC resolution adaptation in Vue

Table of contents plan Install Dependencies Intro...

Docker uses a single image to map to multiple ports

need: The official website's resource server ...

MySQL5.6.31 winx64.zip installation and configuration tutorial

#1. Download # #2. Unzip to local and modify nece...

How to use Docker containers to implement proxy forwarding and data backup

Preface When we deploy applications to servers as...