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