_forms.scss 9.3 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
// stylelint-disable selector-no-qualifying-type
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
  padding: $input-btn-padding-y $input-btn-padding-x;
Mark Otto's avatar
Mark Otto committed
11
  font-size: $font-size-base;
12
  line-height: $input-btn-line-height;
Mark Otto's avatar
Mark Otto committed
13
14
  color: $input-color;
  background-color: $input-bg;
15
16
  // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214.
  background-image: none;
17
  background-clip: padding-box;
18
  border: $input-btn-border-width solid $input-border-color;
19

Chris Rebert's avatar
Chris Rebert committed
20
  // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
21
22
23
24
25
26
27
28
  @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
29
  @include box-shadow($input-box-shadow);
30
  @include transition($input-transition);
Mark Otto's avatar
Mark Otto committed
31

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

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

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

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

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

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

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

83
84
85
86
87
88
89

//
// Labels
//

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

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

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

111

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

125

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

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

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

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

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

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

182

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

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

Mark Otto's avatar
Mark Otto committed
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// 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
216
217
218
// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
219

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

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

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

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

243
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
244
.form-check-inline {
245
  display: inline-block;
246
  margin-right: $form-check-inline-margin-x;
247

248
249
  .form-check-label {
    vertical-align: middle;
250
  }
251
}
252

Mark Otto's avatar
Mark Otto committed
253

254
// Form validation
Mark Otto's avatar
Mark Otto committed
255
//
256
257
258
259
// 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.
260

261
262
@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
263

264
265
// Inline forms
//
266
267
268
269
270
271
// 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).
272
273

.form-inline {
274
275
  display: flex;
  flex-flow: row wrap;
276
  align-items: center; // Prevent shorter elements from growing to same height as others (e.g., small buttons growing to normal sized button height)
277
278
279
280
281
282

  // 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%;
283
  }
284

285
  // Kick in the inline
286
  @include media-breakpoint-up(sm) {
287
    label {
288
289
290
      display: flex;
      align-items: center;
      justify-content: center;
291
292
293
      margin-bottom: 0;
    }

294
    // Inline-block all the things for "inline"
295
    .form-group {
296
297
298
      display: flex;
      flex: 0 0 auto;
      flex-flow: row wrap;
299
      align-items: center;
300
301
      margin-bottom: 0;
    }
302

Mark Otto's avatar
Mark Otto committed
303
    // Allow folks to *not* use `.form-group`
304
305
    .form-control {
      display: inline-block;
306
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
307
      vertical-align: middle;
308
    }
Mark Otto's avatar
Mark Otto committed
309

310
    // Make static controls behave like regular ones
Mark Otto's avatar
Mark Otto committed
311
    .form-control-plaintext {
312
313
314
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
315
    .input-group {
316
      width: auto;
317
    }
318
319

    // Remove default margin on radios/checkboxes that were used for stacking, and
320
    // then undo the floating of radios and checkboxes to match.
321
    .form-check {
322
323
324
      display: flex;
      align-items: center;
      justify-content: center;
325
      width: auto;
326
327
328
      margin-top: 0;
      margin-bottom: 0;
    }
329
330
331
332
    .form-check-label {
      padding-left: 0;
    }
    .form-check-input {
333
      position: relative;
Mark Otto's avatar
Mark Otto committed
334
335
      margin-top: 0;
      margin-right: $form-check-input-margin-x;
336
337
      margin-left: 0;
    }
338

339
340
    // Custom form controls
    .custom-control {
341
342
343
      display: flex;
      align-items: center;
      justify-content: center;
344
345
346
347
348
      padding-left: 0;
    }
    .custom-control-indicator {
      position: static;
      display: inline-block;
Mark Otto's avatar
Mark Otto committed
349
      margin-right: $form-check-input-margin-x; // Flexbox alignment means we lose our HTML space here, so we compensate.
350
351
352
      vertical-align: text-bottom;
    }

Mark Otto's avatar
Mark Otto committed
353
    // Re-override the feedback icon.
354
355
356
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
357
  }
358
}