_forms.scss 8.48 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
2
// scss-lint:disable QualifyingElement

3
//
4
// Textual form controls
Mark Otto's avatar
Mark Otto committed
5
6
7
8
9
//

.form-control {
  display: block;
  width: 100%;
10
  // // Make inputs at least the height of their button counterpart (base line-height + padding + border)
11
  // height: $input-height;
12
  padding: $input-padding-y $input-padding-x;
Mark Otto's avatar
Mark Otto committed
13
  font-size: $font-size-base;
14
  line-height: $input-line-height;
Mark Otto's avatar
Mark Otto committed
15
16
  color: $input-color;
  background-color: $input-bg;
17
18
  // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214.
  background-image: none;
19
  background-clip: padding-box;
20
  border: $input-btn-border-width solid $input-border-color;
Chris Rebert's avatar
Chris Rebert committed
21
  // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
22
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
23
  @include box-shadow($input-box-shadow);
Mark Otto's avatar
Mark Otto committed
24
  @include transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s);
Mark Otto's avatar
Mark Otto committed
25

Mark Otto's avatar
Mark Otto committed
26
27
28
  // Unstyle the caret on `<select>`s in IE10+.
  &::-ms-expand {
    background-color: transparent;
Mark Otto's avatar
Mark Otto committed
29
    border: 0;
Mark Otto's avatar
Mark Otto committed
30
31
  }

32
  // Customize the `:focus` state to imitate native WebKit styles.
Mark Otto's avatar
Mark Otto committed
33
  @include form-control-focus();
Mark Otto's avatar
Mark Otto committed
34

35
  // Placeholder
36
  &::placeholder {
Mark Otto's avatar
Mark Otto committed
37
    color: $input-color-placeholder;
38
39
    // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
    opacity: 1;
40
  }
41

Mark Otto's avatar
Mark Otto committed
42
  // Disabled and read-only inputs
43
44
45
46
  //
  // HTML5 says that controls under a fieldset > legend:first-child won't be
  // disabled if the fieldset is disabled. Due to implementation difficulty, we
  // don't honor that edge case; we style them as disabled anyway.
Chris Rebert's avatar
Chris Rebert committed
47
  &:disabled,
48
  &[readonly] {
Mark Otto's avatar
Mark Otto committed
49
    background-color: $input-bg-disabled;
50
51
    // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
    opacity: 1;
Mark Otto's avatar
Mark Otto committed
52
  }
Mark Otto's avatar
Mark Otto committed
53

54
  &:disabled {
Mark Otto's avatar
Mark Otto committed
55
    cursor: $cursor-disabled;
56
  }
Mark Otto's avatar
Mark Otto committed
57
}
Mark Otto's avatar
Mark Otto committed
58

59
select.form-control {
vsn4ik's avatar
vsn4ik committed
60
  &:not([size]):not([multiple]) {
61
62
    height: $input-height;
  }
63
64
65
66
67
68
69
70
71
72

  &:focus::-ms-value {
    // Suppress the nested default white text on blue background highlight given to
    // the selected option text when the (still closed) <select> receives focus
    // in IE and (under certain conditions) Edge, as it looks bad and cannot be made to
    // match the appearance of the native widget.
    // See https://github.com/twbs/bootstrap/issues/19398.
    color: $input-color;
    background-color: $input-bg;
  }
73
}
Mark Otto's avatar
Mark Otto committed
74

75
// Make file inputs better match text inputs by forcing them to new lines.
76
77
.form-control-file,
.form-control-range {
78
79
  display: block;
}
80

81
82
83
84
85
86
87

//
// Labels
//

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
88
.col-form-label {
89
90
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
91
92
93
  margin-bottom: 0; // Override the `<label>` default
}

94
.col-form-label-lg {
95
96
97
98
99
  padding-top: $input-padding-y-lg;
  padding-bottom: $input-padding-y-lg;
  font-size: $font-size-lg;
}

100
.col-form-label-sm {
101
102
103
104
105
  padding-top: $input-padding-y-sm;
  padding-bottom: $input-padding-y-sm;
  font-size: $font-size-sm;
}

106

Patrick H. Lauke's avatar
Patrick H. Lauke committed
107
108
109
110
111
112
//
// Legends
//

// For use with horizontal and inline forms, when you need the legend text to
// be the same size as regular labels, and to align with the form controls.
113
.col-form-legend {
114
115
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
Patrick H. Lauke's avatar
Patrick H. Lauke committed
116
117
118
119
  margin-bottom: 0;
  font-size: $font-size-base;
}

120

121
122
123
124
125
126
// Static form control text
//
// Apply class to an element to make any string of text align with labels in a
// horizontal form layout.

.form-control-static {
127
  min-height: $input-height;
128
  // Size it appropriately next to real form controls
129
130
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  // Remove default margin from `p`
  margin-bottom: 0;

  &.form-control-sm,
  &.form-control-lg {
    padding-right: 0;
    padding-left: 0;
  }
}


// Form control sizing
//
// Build on `.form-control` with modifier classes to decrease or increase the
// height and font-size of form controls.
//
// The `.form-group-* form-control` variations are sadly duplicated to avoid the
// issue documented in https://github.com/twbs/bootstrap/issues/15074.

.form-control-sm {
151
  padding: $input-padding-y-sm $input-padding-x-sm;
152
  font-size: $font-size-sm;
153
  @include border-radius($input-border-radius-sm);
154
155
}

156
157
158
159
160
161
select.form-control-sm {
  &:not([size]):not([multiple]) {
    height: $input-height-sm;
  }
}

162
.form-control-lg {
163
  padding: $input-padding-y-lg $input-padding-x-lg;
164
  font-size: $font-size-lg;
165
  @include border-radius($input-border-radius-lg);
166
167
}

168
169
170
171
172
173
select.form-control-lg {
  &:not([size]):not([multiple]) {
    height: $input-height-lg;
  }
}

174

Mark Otto's avatar
Mark Otto committed
175
176
177
178
179
180
// Form groups
//
// Designed to help with the organization and spacing of vertical forms. For
// horizontal forms, use the predefined grid classes.

.form-group {
Mark Otto's avatar
Mark Otto committed
181
  margin-bottom: $form-group-margin-bottom;
Mark Otto's avatar
Mark Otto committed
182
183
}

184
185
186
187
188
.form-text {
  display: block;
  margin-top: ($spacer * .25);
}

Mark Otto's avatar
Mark Otto committed
189
190
191
192

// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
193

Mark Otto's avatar
Mark Otto committed
194
.form-check {
195
  position: relative;
196
  display: block;
197
  margin-bottom: ($spacer * .75);
Mark Otto's avatar
Mark Otto committed
198

Mark Otto's avatar
Mark Otto committed
199
  // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
linting    
Mark Otto committed
200
  + .form-check {
Mark Otto's avatar
Mark Otto committed
201
202
    margin-top: -.25rem;
  }
Mark Otto's avatar
Mark Otto committed
203

Mark Otto's avatar
Mark Otto committed
204
205
  &.disabled {
    .form-check-label {
206
      color: $text-muted;
Mark Otto's avatar
Mark Otto committed
207
      cursor: $cursor-disabled;
Mark Otto's avatar
Mark Otto committed
208
    }
Mark Otto's avatar
Mark Otto committed
209
  }
210
}
Mark Otto's avatar
Mark Otto committed
211
212
213
214
215
216
217
218

.form-check-label {
  padding-left: 1.25rem;
  margin-bottom: 0; // Override default `<label>` bottom margin
  cursor: pointer;
}

.form-check-input {
219
  position: absolute;
220
221
  margin-top: .25rem;
  margin-left: -1.25rem;
222

Mark Otto's avatar
Mark Otto committed
223
224
225
  &:only-child {
    position: static;
  }
Mark Otto's avatar
Mark Otto committed
226
}
227

228
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
229
.form-check-inline {
230
  position: relative;
231
  display: inline-block;
232
  padding-left: 1.25rem;
Mark Otto's avatar
Mark Otto committed
233
  margin-bottom: 0; // Override default `<label>` bottom margin
234
  vertical-align: middle;
235
  cursor: pointer;
236

Mark Otto's avatar
Mark Otto committed
237
238
  + .form-check-inline {
    margin-left: .75rem;
239
  }
Mark Otto's avatar
Mark Otto committed
240

241
  &.disabled {
242
    color: $text-muted;
Mark Otto's avatar
Mark Otto committed
243
    cursor: $cursor-disabled;
244
245
  }
}
246

Mark Otto's avatar
Mark Otto committed
247

Mark Otto's avatar
Mark Otto committed
248
249
250
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
251

252
.form-control-feedback {
253
  margin-top: ($spacer * .25);
254
255
}

256
257
.form-control-success,
.form-control-warning,
Mark Otto's avatar
Mark Otto committed
258
.form-control-danger {
259
  padding-right: ($input-padding-x * 3);
260
  background-repeat: no-repeat;
261
262
  background-position: center right ($input-height / 4);
  background-size: ($input-height / 2) ($input-height / 2);
263
264
}

Mark Otto's avatar
Mark Otto committed
265
// Form validation states
266
.has-success {
267
  @include form-control-validation($brand-success);
268
269

  .form-control-success {
270
    background-image: $form-icon-success;
271
  }
272
}
273

274
.has-warning {
275
  @include form-control-validation($brand-warning);
276
277

  .form-control-warning {
278
    background-image: $form-icon-warning;
279
  }
280
}
281

282
.has-danger {
283
  @include form-control-validation($brand-danger);
284

Mark Otto's avatar
Mark Otto committed
285
  .form-control-danger {
286
    background-image: $form-icon-danger;
287
  }
288
}
289

Mark Otto's avatar
Mark Otto committed
290

291
292
// Inline forms
//
293
294
295
296
297
298
// Make forms appear inline(-block) by adding the `.form-inline` class. Inline
// forms begin stacked on extra small (mobile) devices and then go inline when
// viewports reach <768px.
//
// Requires wrapping inputs and labels with `.form-group` for proper display of
// default HTML form controls and our custom form controls (e.g., input groups).
299
300

.form-inline {
301

302
  // Kick in the inline
303
  @include media-breakpoint-up(sm) {
304
    // Inline-block all the things for "inline"
305
    .form-group {
306
307
308
309
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
310

Mark Otto's avatar
Mark Otto committed
311
    // Allow folks to *not* use `.form-group`
312
313
    .form-control {
      display: inline-block;
314
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
315
      vertical-align: middle;
316
    }
Mark Otto's avatar
Mark Otto committed
317

318
319
320
321
322
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
323
324
325
326
327
328
329
330
331
332
333
    .input-group {
      display: inline-table;
      vertical-align: middle;

      .input-group-addon,
      .input-group-btn,
      .form-control {
        width: auto;
      }
    }

334
335
336
337
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
338

339
    .form-control-label {
340
341
      margin-bottom: 0;
      vertical-align: middle;
342
343
    }

344
    // Remove default margin on radios/checkboxes that were used for stacking, and
345
    // then undo the floating of radios and checkboxes to match.
346
    .form-check {
347
348
349
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
350
      vertical-align: middle;
351
    }
352
353
354
355
    .form-check-label {
      padding-left: 0;
    }
    .form-check-input {
356
      position: relative;
357
358
      margin-left: 0;
    }
359

Mark Otto's avatar
Mark Otto committed
360
    // Re-override the feedback icon.
361
362
363
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
364
  }
365
}