• Mark Otto's avatar
    Merge branch 'master' into v4 · b648a77e
    Mark Otto authored
    Conflicts:
    	Gruntfile.js
    	_config.yml
    	dist/css/bootstrap-theme.css
    	dist/css/bootstrap-theme.min.css
    	dist/css/bootstrap.css
    	dist/css/bootstrap.css.map
    	dist/css/bootstrap.min.css
    	dist/fonts/glyphicons-halflings-regular.eot
    	dist/fonts/glyphicons-halflings-regular.svg
    	dist/fonts/glyphicons-halflings-regular.ttf
    	dist/fonts/glyphicons-halflings-regular.woff
    	docs/_data/glyphicons.yml
    	docs/_includes/components/alerts.html
    	docs/_includes/components/badges.html
    	docs/_includes/components/button-dropdowns.html
    	docs/_includes/components/button-groups.html
    	docs/_includes/components/dropdowns.html
    	docs/_includes/components/glyphicons.html
    	docs/_includes/components/input-groups.html
    	docs/_includes/components/labels.html
    	docs/_includes/components/media.html
    	docs/_includes/components/navbar.html
    	docs/_includes/components/navs.html
    	docs/_includes/components/pagination.html
    	docs/_includes/components/panels.html
    	docs/_includes/components/progress-bars.html
    	docs/_includes/...
    b648a77e
button-group.md 10.54 KiB
layout: page
title: Button group

Group a series of buttons together on a single line with the button group. Add on optional JavaScript radio and checkbox style behavior with our buttons plugin.

Tooltips & popovers in button groups require special setting

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

Ensure correct role and provide a label

In order for assistive technologies – such as screen readers – to convey that a series of buttons is grouped, an appropriate role attribute needs to be provided. For button groups, this would be role="group", while toolbars should have a role="toolbar".

One exception are groups which only contain a single control (for instance the justified button groups with <button> elements) or a dropdown.

In addition, groups and toolbars should be given an explicit label, as most assistive technologies will otherwise not announce them, despite the presence of the correct role attribute. In the examples provided here, we use aria-label, but alternatives such as aria-labelledby can also be used.

Basic example

Wrap a series of buttons with .btn in .btn-group.

{% example html %}

Left Middle Right
{% endexample %}

Button toolbar

Combine sets of button groups into button toolbars for more complex components.

{% example html %}

1 2 3 4
5 6 7
8
{% endexample %}

Sizing

Instead of applying button sizing classes to every button in a group, just add .btn-group-* to the .btn-group.

Left Middle Right

Left Middle Right

Left Middle Right

Left Middle Right

{% highlight html %}

...
...
...
...
{% endhighlight %}

Nesting

Place a .btn-group within another .btn-group when you want dropdown menus mixed with a series of buttons.

{% example html %}

{% endexample %}

Vertical variation

Make a set of buttons appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.

Button Button Button Button

{% highlight html %}

...
{% endhighlight %}

Justified button groups

Make a group of buttons stretch at equal sizes to span the entire width of its parent. Also works with button dropdowns within the button group.

Handling borders

Due to the specific HTML and CSS used to justify buttons (namely display: table-cell), the borders between them are doubled. In regular button groups, margin-left: -1px is used to stack the borders instead of removing them. However, margin doesn't work with display: table-cell. As a result, depending on your customizations to Bootstrap, you may wish to remove or re-color the borders.

With <a> elements

Just wrap a series of .btns in .btn-group.btn-group-justified.

{% example html %}

{% endexample %}

Links acting as buttons

If the <a> elements are used to act as buttons – triggering in-page functionality, rather than navigating to another document or section within the current page – they should also be given an appropriate role="button".

With <button> elements

To use justified button groups with <button> elements, you must wrap each button in a button group. Most browsers don't properly apply our CSS for justification to <button> elements, but since we support button dropdowns, we can work around that.

{% example html %}

Left
Middle
Right
{% endexample %}