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

5

6
//
7
// Textual form controls
Mark Otto's avatar
Mark Otto committed
8
9
10
11
12
//

.form-control {
  display: block;
  width: 100%;
13
14
  // // 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
15
16
17
18
19
  padding: $padding-base-vertical $padding-base-horizontal;
  font-size: $font-size-base;
  line-height: $line-height-base;
  color: $input-color;
  background-color: $input-bg;
20
21
  // 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
22
  border: 1px solid $input-border;
23
24
   // 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
25
  @include box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
26
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
Mark Otto's avatar
Mark Otto committed
27

28
29
30
31
32
33
34
35
  // 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;
  }

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

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

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

59
60
  &[disabled],
  fieldset[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
80
81
82
83
84

//
// Labels
//

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
.form-control-label {
  padding: ($padding-base-vertical + $border-width) $padding-base-horizontal;
  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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// @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;
//     }
//   }
// }
112

Mark Otto's avatar
Mark Otto committed
113
114
115
116
117
118
119

// 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
120
  margin-bottom: $form-group-margin-bottom;
Mark Otto's avatar
Mark Otto committed
121
122
123
124
125
126
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
127
128
129

.radio,
.checkbox {
130
  position: relative;
131
  display: block;
132
133
  // margin-top:    ($spacer * .75);
  margin-bottom: ($spacer * .75);
Mark Otto's avatar
Mark Otto committed
134

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

Mark Otto's avatar
Mark Otto committed
154
155
.radio + .radio,
.checkbox + .checkbox {
156
157
  // Move up sibling radios or checkboxes for tighter spacing
  margin-top: -.25rem;
Mark Otto's avatar
Mark Otto committed
158
}
159

160
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
161
162
.radio-inline,
.checkbox-inline {
163
  position: relative;
164
  display: inline-block;
165
  padding-left: 1.25rem;
166
  margin-bottom: 0;
Mark Otto's avatar
Mark Otto committed
167
  font-weight: normal;
168
  vertical-align: middle;
169
  cursor: pointer;
170
}
Mark Otto's avatar
Mark Otto committed
171
172
173
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
174
  margin-left: .75rem;
175
176
}

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

Mark Otto's avatar
Mark Otto committed
208

209
210
211
212
213
214
// 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
215
  min-height: ($line-height-computed + $font-size-base);
216
  // Size it appropriately next to real form controls
Mark Otto's avatar
Mark Otto committed
217
218
  padding-top: ($padding-base-vertical + 1);
  padding-bottom: ($padding-base-vertical + 1);
219
220
221
222
223
224
  // Remove default margin from `p`
  margin-bottom: 0;

  &.input-lg,
  &.input-sm {
    padding-right: 0;
225
    padding-left: 0;
226
227
228
229
  }
}


Mark Otto's avatar
Mark Otto committed
230
// Form control sizing
Mark Otto's avatar
Mark Otto committed
231
232
233
//
// Build on `.form-control` with modifier classes to decrease or increase the
// height and font-size of form controls.
234
235
236
//
// 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
237

238
239
240
241
242
243
244
.form-control-sm {
  height: $input-height-sm;
  padding: $padding-sm-vertical $padding-sm-horizontal;
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  border-radius: $input-border-radius-sm;
}
Mark Otto's avatar
Mark Otto committed
245

246
247
248
249
250
251
.form-control-lg {
  height: $input-height-lg;
  padding: $padding-lg-vertical $padding-lg-horizontal;
  font-size: $font-size-lg;
  line-height: $line-height-lg;
  border-radius: $input-border-radius-lg;
252
}
253

254
// @include input-size('.input-sm', $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
255

256
257
// .form-group-sm {
//   @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
258

259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//   .form-control-static {
//     height: $input-height-sm;
//     min-height: ($line-height-computed + $font-size-sm);
//     padding: $padding-sm-vertical $padding-sm-horizontal;
//     font-size: $font-size-sm;
//     line-height: $line-height-sm;
//   }
// }

// @include input-size('.input-lg', $input-height-lg, $padding-lg-vertical, $padding-lg-horizontal, $font-size-lg, $line-height-lg, $input-border-radius-lg);

// .form-group-lg {
//   @include input-size('.form-control', $input-height-lg, $padding-lg-vertical, $padding-lg-horizontal, $font-size-lg, $line-height-lg, $input-border-radius-lg);

//   .form-control-static {
//     height: $input-height-lg;
//     min-height: ($line-height-computed + $font-size-lg);
//     padding: $padding-lg-vertical $padding-lg-horizontal;
//     font-size: $font-size-lg;
//     line-height: $line-height-lg;
//   }
// }
281

Mark Otto's avatar
Mark Otto committed
282

Mark Otto's avatar
Mark Otto committed
283
284
285
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
286

287
288
289
290
291
292
.has-feedback {
  // Enable absolute positioning
  position: relative;

  // Ensure icons don't overlap text
  .form-control {
Mark Otto's avatar
Mark Otto committed
293
    padding-right: ($input-height-base * 1.25);
294
  }
295
}
Mark Otto's avatar
Mark Otto committed
296
// Feedback icon
297
298
.form-control-feedback {
  position: absolute;
299
  top: 0;
300
  right: 0;
301
  z-index: 2; // Ensure icon is above input groups
302
  display: block;
Mark Otto's avatar
Mark Otto committed
303
304
305
  width: $input-height-base;
  height: $input-height-base;
  line-height: $input-height-base;
306
  text-align: center;
Kyle's avatar
Kyle committed
307
  pointer-events: none;
308
}
309
310
.input-lg + .form-control-feedback,
.input-group-lg + .form-control-feedback {
Mark Otto's avatar
Mark Otto committed
311
312
313
  width: $input-height-lg;
  height: $input-height-lg;
  line-height: $input-height-lg;
314
}
315
316
.input-sm + .form-control-feedback,
.input-group-sm + .form-control-feedback {
Mark Otto's avatar
Mark Otto committed
317
318
319
  width: $input-height-sm;
  height: $input-height-sm;
  line-height: $input-height-sm;
320
321
}

Mark Otto's avatar
Mark Otto committed
322
// Form validation states
323
.has-success {
Mark Otto's avatar
Mark Otto committed
324
  @include form-control-validation($state-success-text, $state-success-text, $state-success-bg);
325
}
326
.has-warning {
Mark Otto's avatar
Mark Otto committed
327
  @include form-control-validation($state-warning-text, $state-warning-text, $state-warning-bg);
328
}
329
.has-error {
Mark Otto's avatar
Mark Otto committed
330
  @include form-control-validation($state-danger-text, $state-danger-text, $state-danger-bg);
331
}
332

333
334
// Reposition feedback icon if input has visible label above
.has-feedback label {
Mark Otto's avatar
Mark Otto committed
335

336
337
  ~ .form-control-feedback {
    top: ($line-height-computed + 5); // Height of the `label` and its margin
338
  }
339

340
  &.sr-only ~ .form-control-feedback {
341
    top: 0;
342
  }
343
344
345
}


Mark Otto's avatar
Mark Otto committed
346
347
348
349
// 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.
350

351
.help-block {
352
  display: block; // account for any element using help-block
353
354
  margin-top: .25rem;
  margin-bottom: .75rem;
Mark Otto's avatar
Mark Otto committed
355
  color: lighten($text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
356
}
357
358
359
360


// Inline forms
//
361
362
363
364
365
366
// 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).
367
368
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
369
370

.form-inline {
371

372
  // Kick in the inline
373
  @include media-breakpoint-up(sm) {
374
    // Inline-block all the things for "inline"
375
    .form-group {
376
377
378
379
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
380
381
382
383

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

388
389
390
391
392
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
393
394
395
396
397
398
399
400
401
402
403
    .input-group {
      display: inline-table;
      vertical-align: middle;

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

404
405
406
407
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
408

409
410
411
    .control-label {
      margin-bottom: 0;
      vertical-align: middle;
412
413
    }

414
    // Remove default margin on radios/checkboxes that were used for stacking, and
415
    // then undo the floating of radios and checkboxes to match.
416
417
418
419
420
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
421
      vertical-align: middle;
422
423
424
425

      label {
        padding-left: 0;
      }
426
427
428
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
429
      position: relative;
430
431
      margin-left: 0;
    }
432

Mark Otto's avatar
Mark Otto committed
433
    // Re-override the feedback icon.
434
435
436
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
437
  }
438
439
440
441
442
443
444
445
446
}


// 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 {
447

448
449
  // Consistent vertical alignment of radios and checkboxes
  //
450
  // Labels also get some reset styles, but that is scoped to a media query below.
451
452
453
454
  .radio,
  .checkbox,
  .radio-inline,
  .checkbox-inline {
455
    padding-top: ($padding-base-vertical + .1); // Default padding plus a border
456
457
458
    margin-top: 0;
    margin-bottom: 0;
  }
459
460
461
462
  // 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
463
    min-height: ($line-height-computed + ($padding-base-vertical + .1));
464
  }
465
466

  // Make form groups behave like rows
467
  .form-group {
Mark Otto's avatar
Mark Otto committed
468
    @include make-row();
469
470
  }

471
472
  // 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.
473
  @include media-breakpoint-up(sm) {
474
    .control-label {
Mark Otto's avatar
Mark Otto committed
475
      padding-top: ($padding-base-vertical + .1); // Default padding plus a border
476
477
      margin-bottom: 0;
      text-align: right;
478
    }
Mark Otto's avatar
Mark Otto committed
479
  }
480
481
482
483
484
485

  // 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
486
    right: ($grid-gutter-width / 2);
487
  }
488
489
490
491
492
493

  // 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 {
494
    @include media-breakpoint-up(sm) {
495
      .control-label {
Mark Otto's avatar
Mark Otto committed
496
        padding-top: $padding-lg-vertical;
497
498
499
500
      }
    }
  }
  .form-group-sm {
501
    @include media-breakpoint-up(sm) {
502
      .control-label {
Mark Otto's avatar
Mark Otto committed
503
        padding-top: ($padding-sm-vertical + .1);
504
505
506
      }
    }
  }
507
}