_forms.scss 8.62 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;
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);
Mark Otto's avatar
Mark Otto committed
32
  @include transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s);
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 {
Mark Otto's avatar
Mark Otto committed
45
    color: $input-color-placeholder;
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] {
Mark Otto's avatar
Mark Otto committed
57
    background-color: $input-bg-disabled;
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

62
  &:disabled {
Mark Otto's avatar
Mark Otto committed
63
    cursor: $cursor-disabled;
64
  }
Mark Otto's avatar
Mark Otto committed
65
}
Mark Otto's avatar
Mark Otto committed
66

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

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

83
// Make file inputs better match text inputs by forcing them to new lines.
84
85
.form-control-file,
.form-control-range {
86
87
  display: block;
}
88

89
90
91
92
93
94
95

//
// Labels
//

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
96
.col-form-label {
97
98
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
99
100
101
  margin-bottom: 0; // Override the `<label>` default
}

102
.col-form-label-lg {
103
104
105
106
107
  padding-top: $input-padding-y-lg;
  padding-bottom: $input-padding-y-lg;
  font-size: $font-size-lg;
}

108
.col-form-label-sm {
109
110
111
112
113
  padding-top: $input-padding-y-sm;
  padding-bottom: $input-padding-y-sm;
  font-size: $font-size-sm;
}

114

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

128

129
130
131
132
133
134
135
// 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 {
  // Size it appropriately next to real form controls
136
137
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
Mark Otto's avatar
Mark Otto committed
138
  line-height: $input-line-height;
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-padding-y-sm $input-padding-x-sm;
158
  font-size: $font-size-sm;
159
  @include border-radius($input-border-radius-sm);
160
161
}

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

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

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

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
192
193
194
.form-text {
  display: block;
  margin-top: ($spacer * .25);
}

Mark Otto's avatar
Mark Otto committed
195
196
197
198

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

Mark Otto's avatar
Mark Otto committed
200
.form-check {
201
  position: relative;
202
  display: block;
203
  margin-bottom: ($spacer * .75);
Mark Otto's avatar
Mark Otto committed
204

Mark Otto's avatar
Mark Otto committed
205
  // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
linting    
Mark Otto committed
206
  + .form-check {
Mark Otto's avatar
Mark Otto committed
207
208
    margin-top: -.25rem;
  }
Mark Otto's avatar
Mark Otto committed
209

Mark Otto's avatar
Mark Otto committed
210
211
  &.disabled {
    .form-check-label {
212
      color: $text-muted;
Mark Otto's avatar
Mark Otto committed
213
      cursor: $cursor-disabled;
Mark Otto's avatar
Mark Otto committed
214
    }
Mark Otto's avatar
Mark Otto committed
215
  }
216
}
Mark Otto's avatar
Mark Otto committed
217
218
219
220
221
222
223
224

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

.form-check-input {
225
  position: absolute;
226
227
  margin-top: .25rem;
  margin-left: -1.25rem;
228

Mark Otto's avatar
Mark Otto committed
229
230
231
  &:only-child {
    position: static;
  }
Mark Otto's avatar
Mark Otto committed
232
}
233

234
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
235
.form-check-inline {
236
  position: relative;
237
  display: inline-block;
238
  padding-left: 1.25rem;
Mark Otto's avatar
Mark Otto committed
239
  margin-bottom: 0; // Override default `<label>` bottom margin
240
  vertical-align: middle;
241
  cursor: pointer;
242

Mark Otto's avatar
Mark Otto committed
243
244
  + .form-check-inline {
    margin-left: .75rem;
245
  }
Mark Otto's avatar
Mark Otto committed
246

247
  &.disabled {
248
    color: $text-muted;
Mark Otto's avatar
Mark Otto committed
249
    cursor: $cursor-disabled;
250
251
  }
}
252

Mark Otto's avatar
Mark Otto committed
253

Mark Otto's avatar
Mark Otto committed
254
255
256
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
257

258
.form-control-feedback {
259
  margin-top: ($spacer * .25);
260
261
}

262
263
.form-control-success,
.form-control-warning,
Mark Otto's avatar
Mark Otto committed
264
.form-control-danger {
265
  padding-right: ($input-padding-x * 3);
266
  background-repeat: no-repeat;
267
268
  background-position: center right ($input-height / 4);
  background-size: ($input-height / 2) ($input-height / 2);
269
270
}

Mark Otto's avatar
Mark Otto committed
271
// Form validation states
272
.has-success {
273
  @include form-control-validation($brand-success);
274
275

  .form-control-success {
276
    background-image: $form-icon-success;
277
  }
278
}
279

280
.has-warning {
281
  @include form-control-validation($brand-warning);
282
283

  .form-control-warning {
284
    background-image: $form-icon-warning;
285
  }
286
}
287

288
.has-danger {
289
  @include form-control-validation($brand-danger);
290

Mark Otto's avatar
Mark Otto committed
291
  .form-control-danger {
292
    background-image: $form-icon-danger;
293
  }
294
}
295

Mark Otto's avatar
Mark Otto committed
296

297
298
// Inline forms
//
299
300
301
302
303
304
// 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).
305
306

.form-inline {
307

308
  // Kick in the inline
309
  @include media-breakpoint-up(sm) {
310
    // Inline-block all the things for "inline"
311
    .form-group {
312
313
314
315
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
316

Mark Otto's avatar
Mark Otto committed
317
    // Allow folks to *not* use `.form-group`
318
319
    .form-control {
      display: inline-block;
320
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
321
      vertical-align: middle;
322
    }
Mark Otto's avatar
Mark Otto committed
323

324
325
326
327
328
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
329
330
    .input-group {
      display: inline-table;
331
      width: auto;
Mark Otto's avatar
Mark Otto committed
332
333
334
335
336
337
338
339
340
      vertical-align: middle;

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

341
342
343
344
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
345

346
    .form-control-label {
347
348
      margin-bottom: 0;
      vertical-align: middle;
349
350
    }

351
    // Remove default margin on radios/checkboxes that were used for stacking, and
352
    // then undo the floating of radios and checkboxes to match.
353
    .form-check {
354
355
356
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
357
      vertical-align: middle;
358
    }
359
360
361
362
    .form-check-label {
      padding-left: 0;
    }
    .form-check-input {
363
      position: relative;
364
365
      margin-left: 0;
    }
366

Mark Otto's avatar
Mark Otto committed
367
    // Re-override the feedback icon.
368
369
370
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
371
  }
372
}