The use of a single button in a Web page sometimes does not meet our business needs. We often see multiple buttons used together, such as a set of small icon buttons in a rich text editor. This article will introduce in detail the Bootstrap button group
The button group, like the drop-down menu component, needs to rely on the button.js plug-in to run properly. However, we can also directly call only the bootstrap.js file. Because this file has integrated button.js plug-in function
Similarly, because Bootstrap’s component interaction effects all rely on plug-ins written by the jQuery library, jquery.js must be loaded before using bootstrap.js Only then will the effect be produced
The button group structure is very simple. Use a container named "btn-group" and put multiple buttons into this container
In order to convey the correct grouping of buttons to screen reader users, you need to provide an appropriaterole
Attributes. For button groups, it should berole="group"
, for toolbar (toolbar) it should berole="toolbar"
In addition, button groups and toolbars An explicit label should be given, as most assistive technologies will not read them correctly despite setting the correctrole
attributes. You can usearia-label
or aria-labelledby
In addition to the
In the rich text editor, group button groups together, such as copy, cut and paste a group; left-aligned, middle-aligned, Align right and align one group to the other. The Bootstrap framework button toolbar also provides such a production method. You only need to place the button group "btn-group" in a large container "btn-toolbar" by group
In the blog post introducing form buttons, we know that buttons are divided into three categories: btn-lg, btn-sm and btn-xs name to adjust the padding, font-size, line-height and border-radius property values to change the button size. Then we can also use a similar method to determine the size of the button group:
☑ .btn-group-lg: Large button group
☑ .btn-group-sm: Small button group
☑ .btn-group-xs: Ultra-small button group
Just append the corresponding class name to the ".btn-group" class name to get button groups of different sizes
Many times, we often arrange drop-down menus and ordinary button groups in Together, we achieve an effect similar to a navigation menu. When using it, you only need to change the "dropdown" container of the original drop-down menu to "btn-group" and put it at the same level as the ordinary button
By default, button groups are displayed horizontally. But in actual application, you will always encounter the effect of vertical display. This style is also provided in the Bootstrap framework. Just change the "btn-group" class name of the horizontal grouping to "btn-group-vertical"
The effect of the equal divided button is particularly practical on the mobile terminal. The entire button group width is 100% of the container, and each button in the button group divides the entire container width equally. For example, if there are five buttons in the button group, then each button is 20% wide, if there are four buttons, then each button is 25% wide, and so on. Equally divided buttons are also common. It is called an adaptive group button, and its implementation method is also very simple. You only need to append a "btn-group-justified" class name to the button group "btn-group"
. The implementation principle is very simple. Simulate "btn-group-justified" as a table (display:table), and simulate the buttons inside as table cells (display:table-cell)
[Note] When making equal button groups , try to use thetag element to make buttons, because when using the
.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%; }
为了将元素用于两端对齐的按钮组中,必须将每个按钮包裹进一个按钮组中。因为大部分的浏览器不能将CSS 应用到对齐的
元素上,但是,可以用按钮式下拉菜单来解决这个问题
The above is the detailed content of Detailed introduction to Bootstrap button group. For more information, please follow other related articles on the PHP Chinese website!