_button-group.scss 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // stylelint-disable selector-no-qualifying-type
  2. // Make the div behave like a button
  3. .btn-group,
  4. .btn-group-vertical {
  5. position: relative;
  6. display: inline-flex;
  7. vertical-align: middle; // match .btn alignment given font-size hack above
  8. > .btn {
  9. position: relative;
  10. flex: 0 1 auto;
  11. // Bring the hover, focused, and "active" buttons to the front to overlay
  12. // the borders properly
  13. @include hover {
  14. z-index: 2;
  15. }
  16. &:focus,
  17. &:active,
  18. &.active {
  19. z-index: 2;
  20. }
  21. }
  22. // Prevent double borders when buttons are next to each other
  23. .btn + .btn,
  24. .btn + .btn-group,
  25. .btn-group + .btn,
  26. .btn-group + .btn-group {
  27. margin-left: -$input-btn-border-width;
  28. }
  29. }
  30. // Optional: Group multiple button groups together for a toolbar
  31. .btn-toolbar {
  32. display: flex;
  33. flex-wrap: wrap;
  34. justify-content: flex-start;
  35. .input-group {
  36. width: auto;
  37. }
  38. }
  39. .btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
  40. border-radius: 0;
  41. }
  42. // Set corners individual because sometimes a single button can be in a .btn-group
  43. // and we need :first-child and :last-child to both match
  44. .btn-group > .btn:first-child {
  45. margin-left: 0;
  46. &:not(:last-child):not(.dropdown-toggle) {
  47. @include border-right-radius(0);
  48. }
  49. }
  50. // Need .dropdown-toggle since :last-child doesn't apply given a .dropdown-menu
  51. // immediately after it
  52. .btn-group > .btn:last-child:not(:first-child),
  53. .btn-group > .dropdown-toggle:not(:first-child) {
  54. @include border-left-radius(0);
  55. }
  56. // Custom edits for including btn-groups within btn-groups (useful for including
  57. // dropdown buttons within a btn-group)
  58. .btn-group > .btn-group {
  59. float: left;
  60. }
  61. .btn-group > .btn-group:not(:first-child):not(:last-child) > .btn {
  62. border-radius: 0;
  63. }
  64. .btn-group > .btn-group:first-child:not(:last-child) {
  65. > .btn:last-child,
  66. > .dropdown-toggle {
  67. @include border-right-radius(0);
  68. }
  69. }
  70. .btn-group > .btn-group:last-child:not(:first-child) > .btn:first-child {
  71. @include border-left-radius(0);
  72. }
  73. // Sizing
  74. //
  75. // Remix the default button sizing classes into new ones for easier manipulation.
  76. .btn-group-sm > .btn { @extend .btn-sm; }
  77. .btn-group-lg > .btn { @extend .btn-lg; }
  78. //
  79. // Split button dropdowns
  80. //
  81. .btn + .dropdown-toggle-split {
  82. padding-right: $input-btn-padding-x * .75;
  83. padding-left: $input-btn-padding-x * .75;
  84. &::after {
  85. margin-left: 0;
  86. }
  87. }
  88. .btn-sm + .dropdown-toggle-split {
  89. padding-right: $input-btn-padding-x-sm * .75;
  90. padding-left: $input-btn-padding-x-sm * .75;
  91. }
  92. .btn-lg + .dropdown-toggle-split {
  93. padding-right: $input-btn-padding-x-lg * .75;
  94. padding-left: $input-btn-padding-x-lg * .75;
  95. }
  96. // The clickable button for toggling the menu
  97. // Set the same inset shadow as the :active state
  98. .btn-group.show .dropdown-toggle {
  99. @include box-shadow($btn-active-box-shadow);
  100. // Show no shadow for `.btn-link` since it has no other button styles.
  101. &.btn-link {
  102. @include box-shadow(none);
  103. }
  104. }
  105. //
  106. // Vertical button groups
  107. //
  108. .btn-group-vertical {
  109. flex-direction: column;
  110. align-items: flex-start;
  111. justify-content: center;
  112. .btn,
  113. .btn-group {
  114. width: 100%;
  115. }
  116. > .btn + .btn,
  117. > .btn + .btn-group,
  118. > .btn-group + .btn,
  119. > .btn-group + .btn-group {
  120. margin-top: -$input-btn-border-width;
  121. margin-left: 0;
  122. }
  123. > .btn {
  124. &:not(:first-child):not(:last-child) {
  125. border-radius: 0;
  126. }
  127. &:first-child:not(:last-child) {
  128. @include border-bottom-radius(0);
  129. }
  130. &:last-child:not(:first-child) {
  131. @include border-top-radius(0);
  132. }
  133. }
  134. > .btn-group:not(:first-child):not(:last-child) > .btn {
  135. border-radius: 0;
  136. }
  137. > .btn-group:first-child:not(:last-child) {
  138. > .btn:last-child,
  139. > .dropdown-toggle {
  140. @include border-bottom-radius(0);
  141. }
  142. }
  143. > .btn-group:last-child:not(:first-child) > .btn:first-child {
  144. @include border-top-radius(0);
  145. }
  146. }
  147. // Checkbox and radio options
  148. //
  149. // In order to support the browser's form validation feedback, powered by the
  150. // `required` attribute, we have to "hide" the inputs via `clip`. We cannot use
  151. // `display: none;` or `visibility: hidden;` as that also hides the popover.
  152. // Simply visually hiding the inputs via `opacity` would leave them clickable in
  153. // certain cases which is prevented by using `clip` and `pointer-events`.
  154. // This way, we ensure a DOM element is visible to position the popover from.
  155. //
  156. // See https://github.com/twbs/bootstrap/pull/12794 and
  157. // https://github.com/twbs/bootstrap/pull/14559 for more information.
  158. [data-toggle="buttons"] {
  159. > .btn,
  160. > .btn-group > .btn {
  161. input[type="radio"],
  162. input[type="checkbox"] {
  163. position: absolute;
  164. clip: rect(0,0,0,0);
  165. pointer-events: none;
  166. }
  167. }
  168. }