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

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-btn-padding-y $input-btn-padding-x;
Mark Otto's avatar
Mark Otto committed
13
  font-size: $font-size-base;
14
  line-height: $input-btn-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;
21

Chris Rebert's avatar
Chris Rebert committed
22
  // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
23
24
25
26
27
28
29
30
  @if $enable-rounded {
    // Manually use the if/else instead of the mixin to account for iOS override
    border-radius: $input-border-radius;
  } @else {
    // Otherwise undo the iOS default
    border-radius: 0;
  }

Mark Otto's avatar
Mark Otto committed
31
  @include box-shadow($input-box-shadow);
32
  @include transition($input-transition);
Mark Otto's avatar
Mark Otto committed
33

Mark Otto's avatar
Mark Otto committed
34
35
36
  // Unstyle the caret on `<select>`s in IE10+.
  &::-ms-expand {
    background-color: transparent;
Mark Otto's avatar
Mark Otto committed
37
    border: 0;
Mark Otto's avatar
Mark Otto committed
38
39
  }

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

43
  // Placeholder
44
  &::placeholder {
45
    color: $input-placeholder-color;
46
47
    // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
    opacity: 1;
48
  }
49

Mark Otto's avatar
Mark Otto committed
50
  // Disabled and read-only inputs
51
52
53
54
  //
  // 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
55
  &:disabled,
56
  &[readonly] {
57
    background-color: $input-disabled-bg;
58
59
    // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
    opacity: 1;
Mark Otto's avatar
Mark Otto committed
60
  }
Mark Otto's avatar
Mark Otto committed
61
}
Mark Otto's avatar
Mark Otto committed
62

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

  &: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;
  }
77
}
Mark Otto's avatar
Mark Otto committed
78

79
// Make file inputs better match text inputs by forcing them to new lines.
80
81
.form-control-file,
.form-control-range {
82
83
  display: block;
}
84

85
86
87
88
89
90
91

//
// Labels
//

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
92
.col-form-label {
93
94
  padding-top: calc(#{$input-btn-padding-y} - #{$input-btn-border-width} * 2);
  padding-bottom: calc(#{$input-btn-padding-y} - #{$input-btn-border-width} * 2);
95
96
97
  margin-bottom: 0; // Override the `<label>` default
}

98
.col-form-label-lg {
99
100
  padding-top: calc(#{$input-btn-padding-y-lg} - #{$input-btn-border-width} * 2);
  padding-bottom: calc(#{$input-btn-padding-y-lg} - #{$input-btn-border-width} * 2);
101
102
103
  font-size: $font-size-lg;
}

104
.col-form-label-sm {
105
106
  padding-top: calc(#{$input-btn-padding-y-sm} - #{$input-btn-border-width} * 2);
  padding-bottom: calc(#{$input-btn-padding-y-sm} - #{$input-btn-border-width} * 2);
107
108
109
  font-size: $font-size-sm;
}

110

Patrick H. Lauke's avatar
Patrick H. Lauke committed
111
112
113
114
115
116
//
// 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.
117
.col-form-legend {
118
119
  padding-top: $input-btn-padding-y;
  padding-bottom: $input-btn-padding-y;
Patrick H. Lauke's avatar
Patrick H. Lauke committed
120
121
122
123
  margin-bottom: 0;
  font-size: $font-size-base;
}

124

125
// Readonly controls as plain text
126
//
127
128
// Apply class to a readonly input to make it appear like regular plain
// text (without any border, background color, focus indicator)
129

130
.form-control-plaintext {
131
132
  padding-top: $input-btn-padding-y;
  padding-bottom: $input-btn-padding-y;
Mark Otto's avatar
Mark Otto committed
133
  margin-bottom: 0; // match inputs if this class comes on inputs with default margins
134
  line-height: $input-btn-line-height;
135
  border: solid transparent;
Mark Otto's avatar
use var    
Mark Otto committed
136
  border-width: $input-btn-border-width 0;
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

  &.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 {
155
  padding: $input-btn-padding-y-sm $input-btn-padding-x-sm;
156
  font-size: $font-size-sm;
157
  line-height: $input-btn-line-height-sm;
158
  @include border-radius($input-border-radius-sm);
159
160
}

161
162
select.form-control-sm {
  &:not([size]):not([multiple]) {
163
    height: $input-height-sm;
164
165
166
  }
}

167
.form-control-lg {
168
  padding: $input-btn-padding-y-lg $input-btn-padding-x-lg;
169
  font-size: $font-size-lg;
170
  line-height: $input-btn-line-height-lg;
171
  @include border-radius($input-border-radius-lg);
172
173
}

174
175
select.form-control-lg {
  &:not([size]):not([multiple]) {
176
    height: $input-height-lg;
177
178
179
  }
}

180

Mark Otto's avatar
Mark Otto committed
181
182
183
184
185
186
// 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
187
  margin-bottom: $form-group-margin-bottom;
Mark Otto's avatar
Mark Otto committed
188
189
}

190
191
.form-text {
  display: block;
Mark Otto's avatar
Mark Otto committed
192
  margin-top: $form-text-margin-top;
193
194
}

Mark Otto's avatar
Mark Otto committed
195

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Form grid
//
// Special replacement for our grid system's `.row` for tighter form layouts.

.form-row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -5px;
  margin-left: -5px;

  > .col,
  > [class*="col-"] {
    padding-right: 5px;
    padding-left: 5px;
  }
}


Mark Otto's avatar
Mark Otto committed
214
215
216
// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
217

Mark Otto's avatar
Mark Otto committed
218
.form-check {
219
  position: relative;
220
  display: block;
Mark Otto's avatar
Mark Otto committed
221
  margin-bottom: $form-check-margin-bottom;
Mark Otto's avatar
Mark Otto committed
222

Mark Otto's avatar
Mark Otto committed
223
224
  &.disabled {
    .form-check-label {
225
      color: $text-muted;
Mark Otto's avatar
Mark Otto committed
226
    }
Mark Otto's avatar
Mark Otto committed
227
  }
228
}
Mark Otto's avatar
Mark Otto committed
229
230

.form-check-label {
Mark Otto's avatar
Mark Otto committed
231
  padding-left: $form-check-input-gutter;
Mark Otto's avatar
Mark Otto committed
232
233
234
235
  margin-bottom: 0; // Override default `<label>` bottom margin
}

.form-check-input {
236
  position: absolute;
Mark Otto's avatar
Mark Otto committed
237
238
  margin-top: $form-check-input-margin-y;
  margin-left: -$form-check-input-gutter;
Mark Otto's avatar
Mark Otto committed
239
}
240

241
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
242
.form-check-inline {
243
244
  display: inline-block;

245
246
  .form-check-label {
    vertical-align: middle;
247
  }
Mark Otto's avatar
Mark Otto committed
248

249
  + .form-check-inline {
Mark Otto's avatar
Mark Otto committed
250
    margin-left: $form-check-inline-margin-x;
251
252
  }
}
253

Mark Otto's avatar
Mark Otto committed
254

255
// Form validation
Mark Otto's avatar
Mark Otto committed
256
//
257
258
259
260
// Provide feedback to users when form field values are valid or invalid. Works
// primarily for client-side validation via scoped `:invalid` and `:valid`
// pseudo-classes but also includes `.is-invalid` and `.is-valid` classes for
// server side validation.
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
.invalid-feedback {
  display: none;
  margin-top: .25rem;
  font-size: .875rem;
  color: $form-feedback-invalid-color;
}

.invalid-tooltip {
  position: absolute;
  top: 100%;
  z-index: 5;
  display: none;
  width: 250px;
  padding: .5rem;
  margin-top: .1rem;
  font-size: .875rem;
  line-height: 1;
  color: #fff;
  background-color: rgba($form-feedback-invalid-color,.8);
  border-radius: .2rem;
}

284
285
@include form-validation-state("valid", $form-feedback-valid-color);
@include form-validation-state("invalid", $form-feedback-invalid-color);
Mark Otto's avatar
Mark Otto committed
286

287
288
// Inline forms
//
289
290
291
292
293
294
// 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).
295
296

.form-inline {
297
298
  display: flex;
  flex-flow: row wrap;
299
  align-items: center; // Prevent shorter elements from growing to same height as others (e.g., small buttons growing to normal sized button height)
300
301
302
303
304
305

  // Because we use flex, the initial sizing of checkboxes is collapsed and
  // doesn't occupy the full-width (which is what we want for xs grid tier),
  // so we force that here.
  .form-check {
    width: 100%;
306
  }
307

308
  // Kick in the inline
309
  @include media-breakpoint-up(sm) {
310
    label {
311
312
313
      display: flex;
      align-items: center;
      justify-content: center;
314
315
316
      margin-bottom: 0;
    }

317
    // Inline-block all the things for "inline"
318
    .form-group {
319
320
321
      display: flex;
      flex: 0 0 auto;
      flex-flow: row wrap;
322
      align-items: center;
323
324
      margin-bottom: 0;
    }
325

Mark Otto's avatar
Mark Otto committed
326
    // Allow folks to *not* use `.form-group`
327
328
    .form-control {
      display: inline-block;
329
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
330
      vertical-align: middle;
331
    }
Mark Otto's avatar
Mark Otto committed
332

333
    // Make static controls behave like regular ones
Mark Otto's avatar
Mark Otto committed
334
    .form-control-plaintext {
335
336
337
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
338
    .input-group {
339
      width: auto;
340
    }
341

342
    .form-control-label {
343
344
      margin-bottom: 0;
      vertical-align: middle;
345
346
    }

347
    // Remove default margin on radios/checkboxes that were used for stacking, and
348
    // then undo the floating of radios and checkboxes to match.
349
    .form-check {
350
351
352
      display: flex;
      align-items: center;
      justify-content: center;
353
      width: auto;
354
355
356
      margin-top: 0;
      margin-bottom: 0;
    }
357
358
359
360
    .form-check-label {
      padding-left: 0;
    }
    .form-check-input {
361
      position: relative;
Mark Otto's avatar
Mark Otto committed
362
363
      margin-top: 0;
      margin-right: $form-check-input-margin-x;
364
365
      margin-left: 0;
    }
366

367
368
    // Custom form controls
    .custom-control {
369
370
371
      display: flex;
      align-items: center;
      justify-content: center;
372
373
374
375
376
      padding-left: 0;
    }
    .custom-control-indicator {
      position: static;
      display: inline-block;
Mark Otto's avatar
Mark Otto committed
377
      margin-right: $form-check-input-margin-x; // Flexbox alignment means we lose our HTML space here, so we compensate.
378
379
380
      vertical-align: text-bottom;
    }

Mark Otto's avatar
Mark Otto committed
381
    // Re-override the feedback icon.
382
383
384
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
385
  }
386
}