_forms.scss 12.5 KB
Newer Older
1
2
3
//
// Forms
// --------------------------------------------------
4

5
6

// todo: turn this into a class
7
label {
8
  margin-bottom: .5rem;
9
}
10

11

12
//
13
// Textual form controls
Mark Otto's avatar
Mark Otto committed
14
15
16
17
18
//

.form-control {
  display: block;
  width: 100%;
19
20
  // // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  // height: $input-height-base;
Mark Otto's avatar
Mark Otto committed
21
22
23
24
25
  padding: $padding-base-vertical $padding-base-horizontal;
  font-size: $font-size-base;
  line-height: $line-height-base;
  color: $input-color;
  background-color: $input-bg;
26
27
  // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214.
  background-image: none;
Mark Otto's avatar
Mark Otto committed
28
  border: 1px solid $input-border;
29
30
   // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
31
  @include box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
32
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
Mark Otto's avatar
Mark Otto committed
33

34
35
36
37
38
39
40
41
  // Make inputs at least the height of their button counterpart (base line-height + padding + border).
  // Only apply the height to textual inputs and some selcts.
  &:not(textarea),
  &:not(select[size]),
  &:not(select[multiple]) {
    height: $input-height-base;
  }

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

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

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

65
66
  &[disabled],
  fieldset[disabled] & {
Mark Otto's avatar
Mark Otto committed
67
    cursor: $cursor-disabled;
68
  }
Mark Otto's avatar
Mark Otto committed
69
}
Mark Otto's avatar
Mark Otto committed
70
71


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

78
// Todo: clear this up
79

80
// Special styles for iOS temporal inputs
81
//
82
// In Mobile Safari, setting `display: block` on temporal inputs causes the
Mark Otto's avatar
Mark Otto committed
83
84
// 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
85
// for Safari. See https://bugs.webkit.org/show_bug.cgi?id=139848
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// @media screen and (-webkit-min-device-pixel-ratio: 0) {
//   input[type="date"],
//   input[type="time"],
//   input[type="datetime-local"],
//   input[type="month"] {
//     line-height: $input-height-base;

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

//     &.input-lg,
//     .input-group-lg & {
//       line-height: $input-height-lg;
//     }
//   }
// }
105

Mark Otto's avatar
Mark Otto committed
106
107
108
109
110
111
112

// 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
113
  margin-bottom: $form-group-margin-bottom;
Mark Otto's avatar
Mark Otto committed
114
115
116
117
118
119
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
120
121
122

.radio,
.checkbox {
123
  position: relative;
124
  display: block;
125
126
  // margin-top:    ($spacer * .75);
  margin-bottom: ($spacer * .75);
Mark Otto's avatar
Mark Otto committed
127

Mark Otto's avatar
Mark Otto committed
128
  label {
129
130
131
    // Ensure the input doesn't jump when there is no text
    min-height: $line-height-computed;
    padding-left: 1.25rem;
132
    margin-bottom: 0;
Mark Otto's avatar
Mark Otto committed
133
    font-weight: normal;
134
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
135
  }
136
}
137
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
138
139
140
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
141
  position: absolute;
142
143
144
  margin-top: .25rem;
  // margin-top: 4px \9;
  margin-left: -1.25rem;
145
}
146

Mark Otto's avatar
Mark Otto committed
147
148
.radio + .radio,
.checkbox + .checkbox {
149
150
  // Move up sibling radios or checkboxes for tighter spacing
  margin-top: -.25rem;
Mark Otto's avatar
Mark Otto committed
151
}
152

153
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
154
155
.radio-inline,
.checkbox-inline {
156
  position: relative;
157
  display: inline-block;
158
  padding-left: 1.25rem;
159
  margin-bottom: 0;
Mark Otto's avatar
Mark Otto committed
160
  font-weight: normal;
161
  vertical-align: middle;
162
  cursor: pointer;
163
}
Mark Otto's avatar
Mark Otto committed
164
165
166
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
167
  margin-left: .75rem;
168
169
}

170
// Apply same disabled cursor tweak as for inputs
171
// Some special care is needed because <label>s don't inherit their parent's `cursor`.
172
//
173
// Note: Neither radios nor checkboxes can be readonly.
174
input[type="radio"],
175
input[type="checkbox"] {
Chris Rebert's avatar
Chris Rebert committed
176
  &:disabled,
177
178
  &.disabled,
  fieldset[disabled] & {
Mark Otto's avatar
Mark Otto committed
179
    cursor: $cursor-disabled;
180
181
182
  }
}
// These classes are used directly on <label>s
183
184
.radio-inline,
.checkbox-inline {
185
  &.disabled,
186
  fieldset[disabled] & {
Mark Otto's avatar
Mark Otto committed
187
    cursor: $cursor-disabled;
188
189
  }
}
190
191
192
193
194
195
// These classes are used on elements with <label> descendants
.radio,
.checkbox {
  &.disabled,
  fieldset[disabled] & {
    label {
Mark Otto's avatar
Mark Otto committed
196
      cursor: $cursor-disabled;
197
198
199
    }
  }
}
200

Mark Otto's avatar
Mark Otto committed
201

202
203
204
205
206
207
// Static form control text
//
// Apply class to a `p` element to make any string of text align with labels in
// a horizontal form layout.

.form-control-static {
Mark Otto's avatar
Mark Otto committed
208
  min-height: ($line-height-computed + $font-size-base);
209
  // Size it appropriately next to real form controls
Mark Otto's avatar
Mark Otto committed
210
211
  padding-top: ($padding-base-vertical + 1);
  padding-bottom: ($padding-base-vertical + 1);
212
213
214
215
216
217
  // Remove default margin from `p`
  margin-bottom: 0;

  &.input-lg,
  &.input-sm {
    padding-right: 0;
218
    padding-left: 0;
219
220
221
222
  }
}


Mark Otto's avatar
Mark Otto committed
223
// Form control sizing
Mark Otto's avatar
Mark Otto committed
224
225
226
//
// Build on `.form-control` with modifier classes to decrease or increase the
// height and font-size of form controls.
227
228
229
//
// The `.form-group-* form-control` variations are sadly duplicated to avoid the
// issue documented in https://github.com/twbs/bootstrap/issues/15074.
Mark Otto's avatar
Mark Otto committed
230

Mark Otto's avatar
Mark Otto committed
231
232
@include input-size('.input-sm', $input-height-sm, $padding-sm-vertical, $padding-sm-horizontal, $font-size-sm, $line-height-sm, $input-border-radius-sm);

233
.form-group-sm {
Mark Otto's avatar
Mark Otto committed
234
  @include input-size('.form-control', $input-height-sm, $padding-sm-vertical, $padding-sm-horizontal, $font-size-sm, $line-height-sm, $input-border-radius-sm);
Mark Otto's avatar
Mark Otto committed
235

236
  .form-control-static {
Mark Otto's avatar
Mark Otto committed
237
    height: $input-height-sm;
Mark Otto's avatar
Mark Otto committed
238
    min-height: ($line-height-computed + $font-size-sm);
Mark Otto's avatar
Mark Otto committed
239
240
241
    padding: $padding-sm-vertical $padding-sm-horizontal;
    font-size: $font-size-sm;
    line-height: $line-height-sm;
242
  }
243
}
244

Mark Otto's avatar
Mark Otto committed
245
246
@include input-size('.input-lg', $input-height-lg, $padding-lg-vertical, $padding-lg-horizontal, $font-size-lg, $line-height-lg, $input-border-radius-lg);

247
.form-group-lg {
Mark Otto's avatar
Mark Otto committed
248
  @include input-size('.form-control', $input-height-lg, $padding-lg-vertical, $padding-lg-horizontal, $font-size-lg, $line-height-lg, $input-border-radius-lg);
Mark Otto's avatar
Mark Otto committed
249

250
  .form-control-static {
Mark Otto's avatar
Mark Otto committed
251
    height: $input-height-lg;
Mark Otto's avatar
Mark Otto committed
252
    min-height: ($line-height-computed + $font-size-lg);
Mark Otto's avatar
Mark Otto committed
253
254
255
    padding: $padding-lg-vertical $padding-lg-horizontal;
    font-size: $font-size-lg;
    line-height: $line-height-lg;
256
  }
257
}
258

Mark Otto's avatar
Mark Otto committed
259

Mark Otto's avatar
Mark Otto committed
260
261
262
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
263

264
265
266
267
268
269
.has-feedback {
  // Enable absolute positioning
  position: relative;

  // Ensure icons don't overlap text
  .form-control {
Mark Otto's avatar
Mark Otto committed
270
    padding-right: ($input-height-base * 1.25);
271
  }
272
}
Mark Otto's avatar
Mark Otto committed
273
// Feedback icon
274
275
.form-control-feedback {
  position: absolute;
276
  top: 0;
277
  right: 0;
278
  z-index: 2; // Ensure icon is above input groups
279
  display: block;
Mark Otto's avatar
Mark Otto committed
280
281
282
  width: $input-height-base;
  height: $input-height-base;
  line-height: $input-height-base;
283
  text-align: center;
Kyle's avatar
Kyle committed
284
  pointer-events: none;
285
}
286
287
.input-lg + .form-control-feedback,
.input-group-lg + .form-control-feedback {
Mark Otto's avatar
Mark Otto committed
288
289
290
  width: $input-height-lg;
  height: $input-height-lg;
  line-height: $input-height-lg;
291
}
292
293
.input-sm + .form-control-feedback,
.input-group-sm + .form-control-feedback {
Mark Otto's avatar
Mark Otto committed
294
295
296
  width: $input-height-sm;
  height: $input-height-sm;
  line-height: $input-height-sm;
297
298
}

Mark Otto's avatar
Mark Otto committed
299
// Form validation states
300
.has-success {
Mark Otto's avatar
Mark Otto committed
301
  @include form-control-validation($state-success-text, $state-success-text, $state-success-bg);
302
}
303
.has-warning {
Mark Otto's avatar
Mark Otto committed
304
  @include form-control-validation($state-warning-text, $state-warning-text, $state-warning-bg);
305
}
306
.has-error {
Mark Otto's avatar
Mark Otto committed
307
  @include form-control-validation($state-danger-text, $state-danger-text, $state-danger-bg);
308
}
309

310
311
// Reposition feedback icon if input has visible label above
.has-feedback label {
Mark Otto's avatar
Mark Otto committed
312

313
314
  ~ .form-control-feedback {
    top: ($line-height-computed + 5); // Height of the `label` and its margin
315
  }
316

317
  &.sr-only ~ .form-control-feedback {
318
    top: 0;
319
  }
320
321
322
}


Mark Otto's avatar
Mark Otto committed
323
324
325
326
// Help text
//
// Apply to any element you wish to create light text for placement immediately
// below a form control. Use for general help, formatting, or instructional text.
327

328
.help-block {
329
  display: block; // account for any element using help-block
330
331
  margin-top: .25rem;
  margin-bottom: .75rem;
Mark Otto's avatar
Mark Otto committed
332
  color: lighten($text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
333
}
334
335
336
337


// Inline forms
//
338
339
340
341
342
343
// 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).
344
345
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
346
347

.form-inline {
348

349
  // Kick in the inline
350
  @include media-breakpoint-up(sm) {
351
    // Inline-block all the things for "inline"
352
    .form-group {
353
354
355
356
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
357
358
359
360

    // In navbar-form, allow folks to *not* use `.form-group`
    .form-control {
      display: inline-block;
361
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
362
      vertical-align: middle;
363
    }
Mark Otto's avatar
Mark Otto committed
364

365
366
367
368
369
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
370
371
372
373
374
375
376
377
378
379
380
    .input-group {
      display: inline-table;
      vertical-align: middle;

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

381
382
383
384
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
385

386
387
388
    .control-label {
      margin-bottom: 0;
      vertical-align: middle;
389
390
    }

391
    // Remove default margin on radios/checkboxes that were used for stacking, and
392
    // then undo the floating of radios and checkboxes to match.
393
394
395
396
397
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
398
      vertical-align: middle;
399
400
401
402

      label {
        padding-left: 0;
      }
403
404
405
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
406
      position: relative;
407
408
      margin-left: 0;
    }
409

Mark Otto's avatar
Mark Otto committed
410
    // Re-override the feedback icon.
411
412
413
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
414
  }
415
416
417
418
419
420
421
422
423
}


// Horizontal forms
//
// Horizontal forms are built on grid classes and allow you to create forms with
// labels on the left and inputs on the right.

.form-horizontal {
424

425
426
  // Consistent vertical alignment of radios and checkboxes
  //
427
  // Labels also get some reset styles, but that is scoped to a media query below.
428
429
430
431
  .radio,
  .checkbox,
  .radio-inline,
  .checkbox-inline {
432
    padding-top: ($padding-base-vertical + .1); // Default padding plus a border
433
434
435
    margin-top: 0;
    margin-bottom: 0;
  }
436
437
438
439
  // Account for padding we're adding to ensure the alignment and of help text
  // and other content below items
  .radio,
  .checkbox {
Mark Otto's avatar
Mark Otto committed
440
    min-height: ($line-height-computed + ($padding-base-vertical + .1));
441
  }
442
443

  // Make form groups behave like rows
444
  .form-group {
Mark Otto's avatar
Mark Otto committed
445
    @include make-row();
446
447
  }

448
449
  // Reset spacing and right align labels, but scope to media queries so that
  // labels on narrow viewports stack the same as a default form example.
450
  @include media-breakpoint-up(sm) {
451
    .control-label {
Mark Otto's avatar
Mark Otto committed
452
      padding-top: ($padding-base-vertical + .1); // Default padding plus a border
453
454
      margin-bottom: 0;
      text-align: right;
455
    }
Mark Otto's avatar
Mark Otto committed
456
  }
457
458
459
460
461
462

  // Validation states
  //
  // Reposition the icon because it's now within a grid column and columns have
  // `position: relative;` on them. Also accounts for the grid gutter padding.
  .has-feedback .form-control-feedback {
Mark Otto's avatar
Mark Otto committed
463
    right: ($grid-gutter-width / 2);
464
  }
465
466
467
468
469
470

  // Form group sizes
  //
  // Quick utility class for applying `.input-lg` and `.input-sm` styles to the
  // inputs and labels within a `.form-group`.
  .form-group-lg {
471
    @include media-breakpoint-up(sm) {
472
      .control-label {
Mark Otto's avatar
Mark Otto committed
473
        padding-top: $padding-lg-vertical;
474
475
476
477
      }
    }
  }
  .form-group-sm {
478
    @include media-breakpoint-up(sm) {
479
      .control-label {
Mark Otto's avatar
Mark Otto committed
480
        padding-top: ($padding-sm-vertical + .1);
481
482
483
      }
    }
  }
484
}