_forms.scss 10.9 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
14
15
  font-size: $font-size-base;
  color: $input-color;
  background-color: $input-bg;
16
17
  // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214.
  background-image: none;
18
  border: $input-btn-border-width solid $input-border-color;
Chris Rebert's avatar
Chris Rebert committed
19
  // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
20
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
21
  @include box-shadow($input-box-shadow);
Mark Otto's avatar
Mark Otto committed
22
  @include transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s);
Mark Otto's avatar
Mark Otto committed
23

24
  // Make inputs at least the height of their button counterpart (base line-height + padding + border).
Chris Rebert's avatar
Chris Rebert committed
25
  // Only apply the height to textual inputs and some selects.
26
27
28
  // &:not(textarea),
  // &:not(select[size]),
  // &:not(select[multiple]) {
29
  //   height: $input-height;
30
  // }
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 {
Mark Otto's avatar
Mark Otto committed
43
    color: $input-color-placeholder;
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] {
Mark Otto's avatar
Mark Otto committed
55
    background-color: $input-bg-disabled;
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

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


66
// Make file inputs better match text inputs by forcing them to new lines.
67
68
.form-control-file,
.form-control-range {
69
70
  display: block;
}
71

72
73
74
75
76
77
78
79

//
// Labels
//

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
.form-control-label {
80
  padding: $input-padding-y $input-padding-x;
81
82
83
84
  margin-bottom: 0; // Override the `<label>` default
}


85
// Todo: clear this up
86

87
// Special styles for iOS temporal inputs
88
//
89
// In Mobile Safari, setting `display: block` on temporal inputs causes the
Mark Otto's avatar
Mark Otto committed
90
91
// text within the input to become vertically misaligned. As a workaround, we
// set a pixel line-height that matches the given height of the input, but only
92
// for Safari. See https://bugs.webkit.org/show_bug.cgi?id=139848
93
//
94
// Note that as of 8.3, iOS doesn't support `week`.
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
_::-webkit-full-page-media, // Hack to make this CSS be Safari-only; see http://browserbu.gs/css-hacks/webkit-full-page-media/
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  &.form-control {
    line-height: $input-height;
  }

  &.input-sm,
  .input-group-sm &.form-control {
    line-height: $input-height-sm;
  }

  &.input-lg,
  .input-group-lg &.form-control {
    line-height: $input-height-lg;
Mark Otto's avatar
Mark Otto committed
113
114
  }
}
115

Mark Otto's avatar
Mark Otto committed
116

117
118
119
120
121
122
// 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 {
123
  min-height: $input-height;
124
  // Size it appropriately next to real form controls
125
126
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  // 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 {
147
  // height: $input-height-sm;
148
  padding: $input-padding-y-sm $input-padding-x-sm;
149
150
  font-size: $font-size-sm;
  line-height: $line-height-sm;
151
  @include border-radius($input-border-radius-sm);
152
153
154
}

.form-control-lg {
155
  // height: $input-height-lg;
156
  padding: $input-padding-y-lg $input-padding-x-lg;
157
158
  font-size: $font-size-lg;
  line-height: $line-height-lg;
159
  @include border-radius($input-border-radius-lg);
160
161
162
}


Mark Otto's avatar
Mark Otto committed
163
164
165
166
167
168
// 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
169
  margin-bottom: $form-group-margin-bottom;
Mark Otto's avatar
Mark Otto committed
170
171
172
173
174
175
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
176
177
178

.radio,
.checkbox {
179
  position: relative;
180
  display: block;
181
182
  // margin-top:    ($spacer * .75);
  margin-bottom: ($spacer * .75);
Mark Otto's avatar
Mark Otto committed
183

Mark Otto's avatar
Mark Otto committed
184
  label {
185
    padding-left: 1.25rem;
186
    margin-bottom: 0;
187
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
188
189
190
191
192

    // When there's no labels, don't position the input.
    input:only-child {
      position: static;
    }
Mark Otto's avatar
Mark Otto committed
193
  }
194
}
195
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
196
197
198
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
199
  position: absolute;
200
201
202
  margin-top: .25rem;
  // margin-top: 4px \9;
  margin-left: -1.25rem;
203
}
204

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

211
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
212
213
.radio-inline,
.checkbox-inline {
214
  position: relative;
215
  display: inline-block;
216
  padding-left: 1.25rem;
217
  margin-bottom: 0;
218
  vertical-align: middle;
219
  cursor: pointer;
220
}
Mark Otto's avatar
Mark Otto committed
221
222
223
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
224
  margin-left: .75rem;
225
226
}

227
// Apply same disabled cursor tweak as for inputs
228
// Some special care is needed because <label>s don't inherit their parent's `cursor`.
229
//
230
// Note: Neither radios nor checkboxes can be readonly.
231
input[type="radio"],
232
input[type="checkbox"] {
Chris Rebert's avatar
Chris Rebert committed
233
  &:disabled,
234
  &.disabled {
Mark Otto's avatar
Mark Otto committed
235
    cursor: $cursor-disabled;
236
237
238
  }
}
// These classes are used directly on <label>s
239
240
.radio-inline,
.checkbox-inline {
241
  &.disabled {
Mark Otto's avatar
Mark Otto committed
242
    cursor: $cursor-disabled;
243
244
  }
}
245
246
247
// These classes are used on elements with <label> descendants
.radio,
.checkbox {
248
  &.disabled {
249
    label {
Mark Otto's avatar
Mark Otto committed
250
      cursor: $cursor-disabled;
251
252
253
    }
  }
}
254

Mark Otto's avatar
Mark Otto committed
255

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

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

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

  .form-control-success {
274
    background-image: $form-icon-success;
275
  }
276
}
277

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

  .form-control-warning {
282
    background-image: $form-icon-warning;
283
  }
284
}
285

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

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

Mark Otto's avatar
Mark Otto committed
294

295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354

// .form-control-success {
//   background-image: url("#{$form-icon-success}");
//   border-color: $brand-success;
// }
//
// .form-control-warning {
//   background-image: url("#{$form-icon-warning}");
//   border-color: $brand-warning;
// }
//
// .form-control-error {
//   background-image: url("#{$form-icon-danger}");
//   border-color: $brand-danger;
// }


// .has-feedback {
//   // Enable absolute positioning
//   position: relative;
//
//   // Ensure icons don't overlap text
//   .form-control {
//     padding-right: ($input-height * 1.25);
//   }
// }
// // Feedback icon
// .form-control-feedback {
//   position: absolute;
//   top: 0;
//   right: 0;
//   z-index: 2; // Ensure icon is above input groups
//   display: block;
//   width: $input-height;
//   height: $input-height;
//   line-height: $input-height;
//   text-align: center;
//   pointer-events: none;
// }
// .input-lg + .form-control-feedback,
// .input-group-lg + .form-control-feedback {
//   width: $input-height-lg;
//   height: $input-height-lg;
//   line-height: $input-height-lg;
// }
// .input-sm + .form-control-feedback,
// .input-group-sm + .form-control-feedback {
//   width: $input-height-sm;
//   height: $input-height-sm;
//   line-height: $input-height-sm;
// }
//
// // Form validation states
// .has-success {
//   @include form-control-validation($state-success-text, $state-success-text, $state-success-bg);
// }
// .has-warning {
//   @include form-control-validation($state-warning-text, $state-warning-text, $state-warning-bg);
// }
355
// .has-danger {
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
//   @include form-control-validation($state-danger-text, $state-danger-text, $state-danger-bg);
// }
//
// // Reposition feedback icon if input has visible label above
// .has-feedback label {
//
//   ~ .form-control-feedback {
//     // TODO: redo this since we nuked the `$line-height-computed`
//     top: 0; // Height of the `label` and its margin
//   }
//
//   &.sr-only ~ .form-control-feedback {
//     top: 0;
//   }
// }
371
372


373
374
// Inline forms
//
375
376
377
378
379
380
// 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).
381
382

.form-inline {
383

384
  // Kick in the inline
385
  @include media-breakpoint-up(sm) {
386
    // Inline-block all the things for "inline"
387
    .form-group {
388
389
390
391
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
392

Mark Otto's avatar
Mark Otto committed
393
    // Allow folks to *not* use `.form-group`
394
395
    .form-control {
      display: inline-block;
396
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
397
      vertical-align: middle;
398
    }
Mark Otto's avatar
Mark Otto committed
399

400
401
402
403
404
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
405
406
407
408
409
410
411
412
413
414
415
    .input-group {
      display: inline-table;
      vertical-align: middle;

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

416
417
418
419
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
420

421
    .form-control-label {
422
423
      margin-bottom: 0;
      vertical-align: middle;
424
425
    }

426
    // Remove default margin on radios/checkboxes that were used for stacking, and
427
    // then undo the floating of radios and checkboxes to match.
428
429
430
431
432
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
433
      vertical-align: middle;
434
435
436
437

      label {
        padding-left: 0;
      }
438
439
440
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
441
      position: relative;
442
443
      margin-left: 0;
    }
444

Mark Otto's avatar
Mark Otto committed
445
    // Re-override the feedback icon.
446
447
448
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
449
  }
450
}