_button-group.scss 5.29 KB
Newer Older
1
2
3
//
// Button groups
// --------------------------------------------------
4

5
// Make the div behave like a button
6
7
.btn-group,
.btn-group-vertical {
8
  position: relative;
9
  display: inline-block;
10
  vertical-align: middle; // match .btn alignment given font-size hack above
Mark Otto's avatar
Mark Otto committed
11

Mark Otto's avatar
Mark Otto committed
12
  > .btn {
13
    position: relative;
Mark Otto's avatar
Mark Otto committed
14
    float: left;
Mark Otto's avatar
Mark Otto committed
15

16
    // Bring the "active" button to the front
17
    &:focus,
18
19
    &:active,
    &.active {
20
21
      z-index: 2;
    }
22
23
24
    @include hover {
      z-index: 2;
    }
Mark Otto's avatar
Mark Otto committed
25
  }
26
27
}

28
// Prevent double borders when buttons are next to each other
Mark Otto's avatar
derp    
Mark Otto committed
29
30
31
32
33
34
35
.btn-group {
  .btn + .btn,
  .btn + .btn-group,
  .btn-group + .btn,
  .btn-group + .btn-group {
    margin-left: -1px;
  }
36
37
}

38
// Optional: Group multiple button groups together for a toolbar
39
.btn-toolbar {
40
  margin-left: -5px; // Offset the first child's margin
Mark Otto's avatar
Mark Otto committed
41
  @include clearfix();
42

43
44
  .btn-group,
  .input-group {
Mark Otto's avatar
Mark Otto committed
45
46
    float: left;
  }
Mark Otto's avatar
Mark Otto committed
47

liuyl's avatar
liuyl committed
48
  > .btn,
49
50
51
  > .btn-group,
  > .input-group {
    margin-left: 5px;
52
  }
53
54
}

55
.btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
56
  border-radius: 0;
57
}
58

59
// 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
60
.btn-group > .btn:first-child {
61
  margin-left: 0;
Mark Otto's avatar
Mark Otto committed
62

63
  &:not(:last-child):not(.dropdown-toggle) {
Mark Otto's avatar
Mark Otto committed
64
    @include border-right-radius(0);
65
  }
66
}
67
// Need .dropdown-toggle since :last-child doesn't apply given a .dropdown-menu immediately after it
68
69
.btn-group > .btn:last-child:not(:first-child),
.btn-group > .dropdown-toggle:not(:first-child) {
Mark Otto's avatar
Mark Otto committed
70
  @include border-left-radius(0);
71
72
}

73
74
75
76
// Custom edits for including btn-groups within btn-groups (useful for including dropdown buttons within a btn-group)
.btn-group > .btn-group {
  float: left;
}
77
.btn-group > .btn-group:not(:first-child):not(:last-child) > .btn {
78
79
  border-radius: 0;
}
80
.btn-group > .btn-group:first-child:not(:last-child) {
81
82
  > .btn:last-child,
  > .dropdown-toggle {
Mark Otto's avatar
Mark Otto committed
83
    @include border-right-radius(0);
84
  }
85
}
86
.btn-group > .btn-group:last-child:not(:first-child) > .btn:first-child {
Mark Otto's avatar
Mark Otto committed
87
  @include border-left-radius(0);
88
89
}

90
91
92
93
94
95
96
// On active and open, don't show outline
.btn-group .dropdown-toggle:active,
.btn-group.open .dropdown-toggle {
  outline: 0;
}


97
98
99
100
// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

Mark Otto's avatar
Mark Otto committed
101
102
103
.btn-group-xs > .btn { @extend .btn-xs; }
.btn-group-sm > .btn { @extend .btn-sm; }
.btn-group-lg > .btn { @extend .btn-lg; }
104

105
106
107
108
109

// Split button dropdowns
// ----------------------

// Give the line between buttons some depth
110
.btn-group > .btn + .dropdown-toggle {
111
  padding-right: 8px;
112
  padding-left: 8px;
113
}
114
.btn-group > .btn-lg + .dropdown-toggle {
115
  padding-right: 12px;
116
  padding-left: 12px;
117
}
118

119
120
121
// The clickable button for toggling the menu
// Remove the gradient and set the same inset shadow as the :active state
.btn-group.open .dropdown-toggle {
Mark Otto's avatar
Mark Otto committed
122
  @include box-shadow(inset 0 3px 5px rgba(0,0,0,.125));
123
124
125

  // Show no shadow for `.btn-link` since it has no other button styles.
  &.btn-link {
Mark Otto's avatar
Mark Otto committed
126
    @include box-shadow(none);
127
  }
128
}
129

Mark Otto's avatar
Mark Otto committed
130

131
132
133
134
// Reposition the caret
.btn .caret {
  margin-left: 0;
}
135
// Carets in other button sizes
136
.btn-lg .caret {
Mark Otto's avatar
Mark Otto committed
137
  border-width: $caret-width-large $caret-width-large 0;
liuyl's avatar
liuyl committed
138
  border-bottom-width: 0;
139
140
}
// Upside down carets for .dropup
141
.dropup .btn-lg .caret {
Mark Otto's avatar
Mark Otto committed
142
  border-width: 0 $caret-width-large $caret-width-large;
143
}
144

145

146
147
148
// Vertical button groups
// ----------------------

Mark Otto's avatar
derp    
Mark Otto committed
149
.btn-group-vertical {
150
  > .btn,
151
152
  > .btn-group,
  > .btn-group > .btn {
153
154
155
156
157
158
159
160
    display: block;
    float: none;
    width: 100%;
    max-width: 100%;
  }

  // Clear floats so dropdown menus can be properly placed
  > .btn-group {
Mark Otto's avatar
Mark Otto committed
161
162
    @include clearfix();

163
164
165
166
167
168
169
170
171
    > .btn {
      float: none;
    }
  }

  > .btn + .btn,
  > .btn + .btn-group,
  > .btn-group + .btn,
  > .btn-group + .btn-group {
172
    margin-top: -1px;
Mark Otto's avatar
derp    
Mark Otto committed
173
    margin-left: 0;
174
175
  }
}
Mark Otto's avatar
derp    
Mark Otto committed
176
177

.btn-group-vertical > .btn {
178
179
180
  &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
liuyl's avatar
liuyl committed
181
  &:first-child:not(:last-child) {
Mark Otto's avatar
Mark Otto committed
182
183
    border-top-right-radius: $border-radius-base;
    @include border-bottom-radius(0);
184
  }
liuyl's avatar
liuyl committed
185
  &:last-child:not(:first-child) {
Mark Otto's avatar
Mark Otto committed
186
187
    border-bottom-left-radius: $border-radius-base;
    @include border-top-radius(0);
188
  }
189
}
Mark Otto's avatar
derp    
Mark Otto committed
190
191
192
.btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn {
  border-radius: 0;
}
193
.btn-group-vertical > .btn-group:first-child:not(:last-child) {
Mark Otto's avatar
derp    
Mark Otto committed
194
195
  > .btn:last-child,
  > .dropdown-toggle {
Mark Otto's avatar
Mark Otto committed
196
    @include border-bottom-radius(0);
Mark Otto's avatar
derp    
Mark Otto committed
197
198
  }
}
199
.btn-group-vertical > .btn-group:last-child:not(:first-child) > .btn:first-child {
Mark Otto's avatar
Mark Otto committed
200
  @include border-top-radius(0);
Mark Otto's avatar
derp    
Mark Otto committed
201
202
}

203

204
// Checkbox and radio options
Mark Otto's avatar
Mark Otto committed
205
206
//
// In order to support the browser's form validation feedback, powered by the
207
208
209
210
// `required` attribute, we have to "hide" the inputs via `clip`. We cannot use
// `display: none;` or `visibility: hidden;` as that also hides the popover.
// Simply visually hiding the inputs via `opacity` would leave them clickable in
// certain cases which is prevented by using `clip` and `pointer-events`.
Mark Otto's avatar
Mark Otto committed
211
212
// This way, we ensure a DOM element is visible to position the popover from.
//
213
214
// See https://github.com/twbs/bootstrap/pull/12794 and
// https://github.com/twbs/bootstrap/pull/14559 for more information.
Mark Otto's avatar
Mark Otto committed
215

216
217
218
219
220
221
[data-toggle="buttons"] {
  > .btn,
  > .btn-group > .btn {
    input[type="radio"],
    input[type="checkbox"] {
      position: absolute;
222
223
      clip: rect(0,0,0,0);
      pointer-events: none;
224
225
    }
  }
226
}