button-groups.less 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // Button groups
  3. // --------------------------------------------------
  4. // Make the div behave like a button
  5. .btn-group,
  6. .btn-group-vertical {
  7. position: relative;
  8. display: inline-block;
  9. vertical-align: middle; // match .btn alignment given font-size hack above
  10. > .btn {
  11. position: relative;
  12. float: left;
  13. // Bring the "active" button to the front
  14. &:hover,
  15. &:focus,
  16. &:active,
  17. &.active {
  18. z-index: 2;
  19. }
  20. }
  21. }
  22. // Prevent double borders when buttons are next to each other
  23. .btn-group {
  24. .btn + .btn,
  25. .btn + .btn-group,
  26. .btn-group + .btn,
  27. .btn-group + .btn-group {
  28. margin-left: -1px;
  29. }
  30. }
  31. // Optional: Group multiple button groups together for a toolbar
  32. .btn-toolbar {
  33. margin-left: -5px; // Offset the first child's margin
  34. &:extend(.clearfix all);
  35. .btn-group,
  36. .input-group {
  37. float: left;
  38. }
  39. > .btn,
  40. > .btn-group,
  41. > .input-group {
  42. margin-left: 5px;
  43. }
  44. }
  45. .btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
  46. border-radius: 0;
  47. }
  48. // Set corners individual because sometimes a single button can be in a .btn-group and we need :first-child and :last-child to both match
  49. .btn-group > .btn:first-child {
  50. margin-left: 0;
  51. &:not(:last-child):not(.dropdown-toggle) {
  52. .border-right-radius(0);
  53. }
  54. }
  55. // Need .dropdown-toggle since :last-child doesn't apply given a .dropdown-menu immediately after it
  56. .btn-group > .btn:last-child:not(:first-child),
  57. .btn-group > .dropdown-toggle:not(:first-child) {
  58. .border-left-radius(0);
  59. }
  60. // Custom edits for including btn-groups within btn-groups (useful for including dropdown buttons within a btn-group)
  61. .btn-group > .btn-group {
  62. float: left;
  63. }
  64. .btn-group > .btn-group:not(:first-child):not(:last-child) > .btn {
  65. border-radius: 0;
  66. }
  67. .btn-group > .btn-group:first-child {
  68. > .btn:last-child,
  69. > .dropdown-toggle {
  70. .border-right-radius(0);
  71. }
  72. }
  73. .btn-group > .btn-group:last-child > .btn:first-child {
  74. .border-left-radius(0);
  75. }
  76. // On active and open, don't show outline
  77. .btn-group .dropdown-toggle:active,
  78. .btn-group.open .dropdown-toggle {
  79. outline: 0;
  80. }
  81. // Sizing
  82. //
  83. // Remix the default button sizing classes into new ones for easier manipulation.
  84. .btn-group-xs > .btn { &:extend(.btn-xs); }
  85. .btn-group-sm > .btn { &:extend(.btn-sm); }
  86. .btn-group-lg > .btn { &:extend(.btn-lg); }
  87. // Split button dropdowns
  88. // ----------------------
  89. // Give the line between buttons some depth
  90. .btn-group > .btn + .dropdown-toggle {
  91. padding-left: 8px;
  92. padding-right: 8px;
  93. }
  94. .btn-group > .btn-lg + .dropdown-toggle {
  95. padding-left: 12px;
  96. padding-right: 12px;
  97. }
  98. // The clickable button for toggling the menu
  99. // Remove the gradient and set the same inset shadow as the :active state
  100. .btn-group.open .dropdown-toggle {
  101. .box-shadow(inset 0 3px 5px rgba(0,0,0,.125));
  102. // Show no shadow for `.btn-link` since it has no other button styles.
  103. &.btn-link {
  104. .box-shadow(none);
  105. }
  106. }
  107. // Reposition the caret
  108. .btn .caret {
  109. margin-left: 0;
  110. }
  111. // Carets in other button sizes
  112. .btn-lg .caret {
  113. border-width: @caret-width-large @caret-width-large 0;
  114. border-bottom-width: 0;
  115. }
  116. // Upside down carets for .dropup
  117. .dropup .btn-lg .caret {
  118. border-width: 0 @caret-width-large @caret-width-large;
  119. }
  120. // Vertical button groups
  121. // ----------------------
  122. .btn-group-vertical {
  123. > .btn,
  124. > .btn-group,
  125. > .btn-group > .btn {
  126. display: block;
  127. float: none;
  128. width: 100%;
  129. max-width: 100%;
  130. }
  131. // Clear floats so dropdown menus can be properly placed
  132. > .btn-group {
  133. &:extend(.clearfix all);
  134. > .btn {
  135. float: none;
  136. }
  137. }
  138. > .btn + .btn,
  139. > .btn + .btn-group,
  140. > .btn-group + .btn,
  141. > .btn-group + .btn-group {
  142. margin-top: -1px;
  143. margin-left: 0;
  144. }
  145. }
  146. .btn-group-vertical > .btn {
  147. &:not(:first-child):not(:last-child) {
  148. border-radius: 0;
  149. }
  150. &:first-child:not(:last-child) {
  151. border-top-right-radius: @border-radius-base;
  152. .border-bottom-radius(0);
  153. }
  154. &:last-child:not(:first-child) {
  155. border-bottom-left-radius: @border-radius-base;
  156. .border-top-radius(0);
  157. }
  158. }
  159. .btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn {
  160. border-radius: 0;
  161. }
  162. .btn-group-vertical > .btn-group:first-child:not(:last-child) {
  163. > .btn:last-child,
  164. > .dropdown-toggle {
  165. .border-bottom-radius(0);
  166. }
  167. }
  168. .btn-group-vertical > .btn-group:last-child:not(:first-child) > .btn:first-child {
  169. .border-top-radius(0);
  170. }
  171. // Justified button groups
  172. // ----------------------
  173. .btn-group-justified {
  174. display: table;
  175. width: 100%;
  176. table-layout: fixed;
  177. border-collapse: separate;
  178. > .btn,
  179. > .btn-group {
  180. float: none;
  181. display: table-cell;
  182. width: 1%;
  183. }
  184. > .btn-group .btn {
  185. width: 100%;
  186. }
  187. > .btn-group .dropdown-menu {
  188. left: auto;
  189. }
  190. }
  191. // Checkbox and radio options
  192. //
  193. // In order to support the browser's form validation feedback, powered by the
  194. // `required` attribute, we have to "hide" the inputs via `clip`. We cannot use
  195. // `display: none;` or `visibility: hidden;` as that also hides the popover.
  196. // Simply visually hiding the inputs via `opacity` would leave them clickable in
  197. // certain cases which is prevented by using `clip` and `pointer-events`.
  198. // This way, we ensure a DOM element is visible to position the popover from.
  199. //
  200. // See https://github.com/twbs/bootstrap/pull/12794 and
  201. // https://github.com/twbs/bootstrap/pull/14559 for more information.
  202. [data-toggle="buttons"] {
  203. > .btn,
  204. > .btn-group > .btn {
  205. input[type="radio"],
  206. input[type="checkbox"] {
  207. position: absolute;
  208. clip: rect(0,0,0,0);
  209. pointer-events: none;
  210. }
  211. }
  212. }