f25f21e2ae28b318acaa59da6dcfe23f7d43ce65.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ---
  2. layout: docs
  3. title: Button group
  4. group: components
  5. ---
  6. 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](../javascript/#buttons).
  7. ## Contents
  8. * Will be replaced with the ToC, excluding the "Contents" header
  9. {:toc}
  10. ## Basic example
  11. Wrap a series of buttons with `.btn` in `.btn-group`.
  12. {% example html %}
  13. <div class="btn-group" role="group" aria-label="Basic example">
  14. <button type="button" class="btn btn-secondary">Left</button>
  15. <button type="button" class="btn btn-secondary">Middle</button>
  16. <button type="button" class="btn btn-secondary">Right</button>
  17. </div>
  18. {% endexample %}
  19. ## Button toolbar
  20. Combine sets of button groups into button toolbars for more complex components.
  21. {% example html %}
  22. <div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
  23. <div class="btn-group" role="group" aria-label="First group">
  24. <button type="button" class="btn btn-secondary">1</button>
  25. <button type="button" class="btn btn-secondary">2</button>
  26. <button type="button" class="btn btn-secondary">3</button>
  27. <button type="button" class="btn btn-secondary">4</button>
  28. </div>
  29. <div class="btn-group" role="group" aria-label="Second group">
  30. <button type="button" class="btn btn-secondary">5</button>
  31. <button type="button" class="btn btn-secondary">6</button>
  32. <button type="button" class="btn btn-secondary">7</button>
  33. </div>
  34. <div class="btn-group" role="group" aria-label="Third group">
  35. <button type="button" class="btn btn-secondary">8</button>
  36. </div>
  37. </div>
  38. {% endexample %}
  39. ## Sizing
  40. Instead of applying button sizing classes to every button in a group, just add `.btn-group-*` to each `.btn-group`, including each one when nesting multiple groups.
  41. <div class="bd-example">
  42. <div class="btn-group btn-group-lg" role="group" aria-label="Large button group">
  43. <button type="button" class="btn btn-secondary">Left</button>
  44. <button type="button" class="btn btn-secondary">Middle</button>
  45. <button type="button" class="btn btn-secondary">Right</button>
  46. </div>
  47. <br>
  48. <div class="btn-group" role="group" aria-label="Default button group">
  49. <button type="button" class="btn btn-secondary">Left</button>
  50. <button type="button" class="btn btn-secondary">Middle</button>
  51. <button type="button" class="btn btn-secondary">Right</button>
  52. </div>
  53. <br>
  54. <div class="btn-group btn-group-sm" role="group" aria-label="Small button group">
  55. <button type="button" class="btn btn-secondary">Left</button>
  56. <button type="button" class="btn btn-secondary">Middle</button>
  57. <button type="button" class="btn btn-secondary">Right</button>
  58. </div>
  59. <br>
  60. <div class="btn-group btn-group-xs" role="group" aria-label="Extra small button group">
  61. <button type="button" class="btn btn-secondary">Left</button>
  62. <button type="button" class="btn btn-secondary">Middle</button>
  63. <button type="button" class="btn btn-secondary">Right</button>
  64. </div>
  65. </div>
  66. {% highlight html %}
  67. <div class="btn-group btn-group-lg" role="group" aria-label="...">...</div>
  68. <div class="btn-group" role="group" aria-label="...">...</div>
  69. <div class="btn-group btn-group-sm" role="group" aria-label="...">...</div>
  70. <div class="btn-group btn-group-xs" role="group" aria-label="...">...</div>
  71. {% endhighlight %}
  72. ## Nesting
  73. Place a `.btn-group` within another `.btn-group` when you want dropdown menus mixed with a series of buttons.
  74. {% example html %}
  75. <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
  76. <button type="button" class="btn btn-secondary">1</button>
  77. <button type="button" class="btn btn-secondary">2</button>
  78. <div class="btn-group" role="group">
  79. <button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  80. Dropdown
  81. </button>
  82. <ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
  83. <li><a href="javascript:;">Dropdown link</a></li>
  84. <li><a href="javascript:;">Dropdown link</a></li>
  85. </ul>
  86. </div>
  87. </div>
  88. {% endexample %}
  89. ## Vertical variation
  90. Make a set of buttons appear vertically stacked rather than horizontally. **Split button dropdowns are not supported here.**
  91. <div class="bd-example">
  92. <div class="btn-group-vertical" role="group" aria-label="Vertical button group">
  93. <button type="button" class="btn btn-secondary">Button</button>
  94. <button type="button" class="btn btn-secondary">Button</button>
  95. <div class="btn-group" role="group">
  96. <button id="btnGroupVerticalDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  97. Dropdown
  98. </button>
  99. <ul class="dropdown-menu" aria-labelledby="btnGroupVerticalDrop1">
  100. <li><a href="javascript:;">Dropdown link</a></li>
  101. <li><a href="javascript:;">Dropdown link</a></li>
  102. </ul>
  103. </div>
  104. <button type="button" class="btn btn-secondary">Button</button>
  105. <button type="button" class="btn btn-secondary">Button</button>
  106. <div class="btn-group" role="group">
  107. <button id="btnGroupVerticalDrop2" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  108. Dropdown
  109. </button>
  110. <ul class="dropdown-menu" aria-labelledby="btnGroupVerticalDrop2">
  111. <li><a href="javascript:;">Dropdown link</a></li>
  112. <li><a href="javascript:;">Dropdown link</a></li>
  113. </ul>
  114. </div>
  115. <div class="btn-group" role="group">
  116. <button id="btnGroupVerticalDrop3" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  117. Dropdown
  118. </button>
  119. <ul class="dropdown-menu" aria-labelledby="btnGroupVerticalDrop3">
  120. <li><a href="javascript:;">Dropdown link</a></li>
  121. <li><a href="javascript:;">Dropdown link</a></li>
  122. </ul>
  123. </div>
  124. <div class="btn-group" role="group">
  125. <button id="btnGroupVerticalDrop4" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  126. Dropdown
  127. </button>
  128. <ul class="dropdown-menu" aria-labelledby="btnGroupVerticalDrop4">
  129. <li><a href="javascript:;">Dropdown link</a></li>
  130. <li><a href="javascript:;">Dropdown link</a></li>
  131. </ul>
  132. </div>
  133. </div>
  134. </div>
  135. {% highlight html %}
  136. <div class="btn-group-vertical">
  137. ...
  138. </div>
  139. {% endhighlight %}
  140. ## Tooltips and popovers
  141. Due to the specific implementation (and some other components), a bit of special casing is required for tooltips and popovers within button groups. **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).