Bootstrap learning button component (1)
This article will introduce to you the button component in Bootstrap. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Related recommendations: "bootstrap Tutorial"
The button group is also an independent component, so you can find the corresponding source code file:
Less: buttons.less
Sass:_buttons.scss
Css:Bootstrap.css 3131 lines ~ 3291 lines
Button group and drop-down menu components Likewise, it needs to rely on the button.js plug-in to function properly.
Structural aspect: Use a container with a class name btn-group and place multiple buttons in this container.
<div> <button> <span></span> </button> … <button> <span></span> </button> </div>
CSS:
.btn-group, .btn-group-vertical { position: relative; display: inline-block; vertical-align: middle; } .btn-group > .btn, .btn-group-vertical > .btn { position: relative; float: left; } .btn-group > .btn:hover, .btn-group-vertical > .btn:hover, .btn-group > .btn:focus, .btn-group-vertical > .btn:focus, .btn-group > .btn:active, .btn-group-vertical > .btn:active, .btn-group > .btn.active, .btn-group-vertical > .btn.active { z-index: 2; } .btn-group > .btn:focus, .btn-group-vertical > .btn:focus { outline: none; } .btn-group .btn + .btn, .btn-group .btn + .btn-group, .btn-group .btn-group + .btn, .btn-group .btn-group + .btn-group { margin-left: -1px; }
In addition to the
The four corners of the button group are rounded, except for the first and last buttons which have edges. Except for the rounded corners, the other buttons do not have rounded corners.
Detailed explanation:
1. Default: all buttons are rounded
2. Except for the first button and the last button, the rounded corners of other buttons are cancelled
3. Only the upper right corner and lower right corner of the last button are rounded
Source code:
.btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) { border-radius: 0; } .btn-group > .btn:first-child { margin-left: 0; } .btn-group > .btn:first-child:not(:last-child):not(.dropdown-toggle) { border-top-right-radius: 0; border-bottom-right-radius: 0; } .btn-group > .btn:last-child:not(:first-child), .btn-group > .dropdown-toggle:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; } .btn-group > .btn-group { float: left; } .btn-group > .btn-group:not(:first-child):not(:last-child) > .btn { border-radius: 0; } .btn-group > .btn-group:first-child> .btn:last-child, .btn-group > .btn-group:first-child> .dropdown-toggle { border-top-right-radius: 0; border-bottom-right-radius: 0; } .btn-group > .btn-group:last-child> .btn:first-child { border-top-left-radius: 0; border-bottom-left-radius: 0; }
Button group toolbar
In a rich text editor, to arrange button groups together, such as copying, cutting, pasting a group, left-aligning, center-aligning, right-aligning and aligning a group at both ends, you need to use the bootstrap frame button tool. Bar btn-toolbar
<div> <div> … </div> <div> … </div> <div> … </div> <div> … </div> </div>
Principle: Mainly let multiple groupings of the container.btn-group elements float, and maintain a left margin of 5px between groups
.btn-toolbar { margin-left: -5px; } .btn-toolbar .btn-group, .btn-toolbar .input-group { float: left; } .btn-toolbar > .btn, .btn-toolbar > .btn-group, .btn-toolbar > .input-group { margin-left: 5px; }
Note that Clear float on btn-toolbar
.btn-toolbar:before, .btn-toolbar:after{ display: table; content: " "; } .btn-toolbar:after{ clear: both; }
Example:
<div> <div> <button> <span></span> </button> <button> <span></span> </button> <button> <span></span> </button> <button> <span></span> </button> </div> <div> <button> <span></span> </button> <button> <span></span> </button> </div> </div>
Button nested grouping
Many times, we put the drop-down menu into a very ordinary button group Arrange them together to achieve an effect similar to a navigation menu:
When using it, you only need to replace the class name of the dropdown container used to create the drop-down menu with btn-group, and Put it at the same level as ordinary buttons:
<div> <button>首页</button> <button>产品展示</button> <button>案例分析</button> <button>联系我们</button> <div> <button> 关于我们<span></span> </button> <ul> <li><a>公司简介</a></li> <li><a>企业文化</a></li> <li><a>组织结构</a></li> <li><a>客服服务</a></li> </ul> </div> </div>
.btn-group > .btn-group { float: left; } .btn-group > .btn-group:not(:first-child):not(:last-child) > .btn { border-radius: 0; } .btn-group > .btn-group:first-child> .btn:last-child, .btn-group > .btn-group:first-child> .dropdown-toggle { border-top-right-radius: 0; border-bottom-right-radius: 0; } .btn-group > .btn-group:last-child> .btn:first-child { border-top-left-radius: 0; border-bottom-left-radius: 0; } .btn-group .dropdown-toggle:active, .btn-group.open .dropdown-toggle { outline: 0; } .btn-group > .btn + .dropdown-toggle { padding-right: 8px; padding-left: 8px; } .btn-group > .btn-lg + .dropdown-toggle { padding-right: 12px; padding-left: 12px; } .btn-group.open .dropdown-toggle { -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125); box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125); } .btn-group.open .dropdown-toggle.btn-link { -webkit-box-shadow: none; box-shadow: none; }
Button vertical grouping
Just replace the horizontal grouping class name .btn-group with .btn-group- Just vertical.
<div> <button>首页</button> <button>产品展示</button> <button>案例分析</button> <button>联系我们</button> <div> <button> 关于我们<span></span> </button> <ul> <li><a>公司简介</a></li> <li><a>企业文化</a></li> <li><a>组织结构</a></li> <li><a>客服服务</a></li> </ul> </div> </div>
.btn-group-vertical > .btn, .btn-group-vertical > .btn-group, .btn-group-vertical > .btn-group > .btn { display: block; float: none; width: 100%; max-width: 100%; } .btn-group-vertical > .btn-group > .btn { float: none; } .btn-group-vertical > .btn + .btn, .btn-group-vertical > .btn + .btn-group, .btn-group-vertical > .btn-group + .btn, .btn-group-vertical > .btn-group + .btn-group { margin-top: -1px; margin-left: 0; } .btn-group-vertical > .btn:not(:first-child):not(:last-child) { border-radius: 0; } .btn-group-vertical > .btn:first-child:not(:last-child) { border-top-right-radius: 4px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; } .btn-group-vertical > .btn:last-child:not(:first-child) { border-top-left-radius: 0; border-top-right-radius: 0; border-bottom-left-radius: 4px; } .btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn { border-radius: 0; } .btn-group-vertical > .btn-group:first-child:not(:last-child) > .btn:last-child, .btn-group-vertical > .btn-group:first-child:not(:last-child) > .dropdown-toggle { border-bottom-right-radius: 0; border-bottom-left-radius: 0; } .btn-group-vertical > .btn-group:last-child:not(:first-child) > .btn:first-child { border-top-left-radius: 0; border-top-right-radius: 0; }
Equally divided buttons are also called adaptive group buttons:
The width of the entire button group is 100% of the container, and each button in the button group is equally divided The width of the entire container. For example, there are five buttons in a button group, and each button is 20% of the container width; there are four buttons in a button group, and each button is 25% of the container width;
Implementation method: Just append a class name .btn-group-justified
<div> <buttton>首页</buttton> <buttton>案例分析</buttton> <buttton>联系我们</buttton> <buttton>关于我们</buttton> </div>
.btn-group-justified { display: table; width: 100%; table-layout: fixed; border-collapse: separate; } .btn-group-justified > .btn, .btn-group-justified > .btn-group { display: table-cell; float: none; width: 1%; } .btn-group-justified > .btn-group .btn { width: 100%; }
to the button group.btn-group to simulate .btn-group-justified into a table (display: table), and put the The button template is simulated as a table cell (display: table-cell).
Note: When making equal button groups, try to use the tag to make buttons, because when using the button tag element, using display: table is not friendly in some browsers.
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of Bootstrap learning button component (1). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To use Bootstrap to layout a website, you need to use a grid system to divide the page into containers, rows, and columns. First add the container, then add the rows in it, add the columns within the row, and finally add the content in the column. Bootstrap's responsive layout function automatically adjusts the layout according to breakpoints (xs, sm, md, lg, xl). Different layouts under different screen sizes can be achieved by using responsive classes.

To create a Bootstrap framework, follow these steps: Install Bootstrap via CDN or install a local copy. Create an HTML document and link Bootstrap CSS to the <head> section. Add Bootstrap JavaScript file to the <body> section. Use the Bootstrap component and customize the stylesheet to suit your needs.

Bootstrap provides a simple guide to setting up navigation bars: Introducing the Bootstrap library to create navigation bar containers Add brand identity Create navigation links Add other elements (optional) Adjust styles (optional)

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

Check and fix Bootstrap Table data source encoding by following these steps: Get the data source and convert it to a string. Use encodeURIComponent() to check the encoding; if it is different, it means that the encoding is not correctly encoded. Use encodeURI() to encode the data source and load it into the Bootstrap Table.

The file upload function can be implemented through Bootstrap. The steps are as follows: introduce Bootstrap CSS and JavaScript files; create file input fields; create file upload buttons; handle file uploads (using FormData to collect data and then send to the server); custom style (optional).

Create a form using the <form> element. Add form elements such as text input boxes, password input boxes, and drop-down lists within the <form> element. Use predefined style classes such as .form-control and .form-group to style the form. Submit the form using the Submit button (<button type="submit">). Use PHP code to process submitted form data.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
