_forms.scss 11.1 KB
Newer Older
1
//
2
// Textual form controls
Mark Otto's avatar
Mark Otto committed
3
4
5
6
7
//

.form-control {
  display: block;
  width: 100%;
8
  // // Make inputs at least the height of their button counterpart (base line-height + padding + border)
9
  // height: $input-height;
10
  padding: $input-padding-y $input-padding-x;
Mark Otto's avatar
Mark Otto committed
11
  font-size: $font-size-base;
12
  line-height: $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
  border: $border-width solid $input-border;
18
19
   // 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
20
  @include box-shadow($input-box-shadow);
Mark Otto's avatar
Mark Otto committed
21
  @include transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s);
Mark Otto's avatar
Mark Otto committed
22

23
24
  // 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.
25
26
27
  // &:not(textarea),
  // &:not(select[size]),
  // &:not(select[multiple]) {
28
  //   height: $input-height;
29
  // }
30

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

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

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

Mark Otto's avatar
Mark Otto committed
47
  // Disabled and read-only inputs
48
49
50
51
  //
  // 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
52
  &:disabled,
Mark Otto's avatar
Mark Otto committed
53
54
  &[readonly],
  fieldset[disabled] & {
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
61
  &[disabled],
  fieldset[disabled] & {
Mark Otto's avatar
Mark Otto committed
62
    cursor: $cursor-disabled;
63
  }
Mark Otto's avatar
Mark Otto committed
64
}
Mark Otto's avatar
Mark Otto committed
65
66


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

73
74
75
76
77
78
79
80

//
// Labels
//

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


86
// Todo: clear this up
87

88
// Special styles for iOS temporal inputs
89
//
90
// In Mobile Safari, setting `display: block` on temporal inputs causes the
Mark Otto's avatar
Mark Otto committed
91
92
// 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
93
// for Safari. See https://bugs.webkit.org/show_bug.cgi?id=139848
94

Mark Otto's avatar
Mark Otto committed
95
96
97
98
99
100
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  input[type="month"] {
    &.form-control {
101
      line-height: $input-height;
Mark Otto's avatar
Mark Otto committed
102
103
104
105
106
107
108
109
110
111
112
113
114
    }

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

    &.input-lg,
    .input-group-lg &.form-control {
      line-height: $input-height-lg;
    }
  }
}
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 + $border-width);
  padding-bottom: ($input-padding-y + $border-width);
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
151
152
153
154
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  border-radius: $input-border-radius-sm;
}

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


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;
Mark Otto's avatar
Mark Otto committed
187
    font-weight: normal;
188
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
189
190
191
192
193

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

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

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

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

Mark Otto's avatar
Mark Otto committed
260

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

265
266
267
.form-control-success,
.form-control-warning,
.form-control-error {
268
  padding-right: ($input-padding-x * 3);
269
270
271
  background-position: center right ($input-height * .25);
  background-size: ($input-height * .65) ($input-height * .65);
  background-repeat: no-repeat;
272
273
}

Mark Otto's avatar
Mark Otto committed
274
// Form validation states
275
.has-success {
276
277
278
279
280
  @include form-control-validation(success, $brand-success);

  .form-control-success {
    background-image: url($form-icon-success);
  }
281
}
282

283
.has-warning {
284
285
286
287
288
  @include form-control-validation(warning, $brand-warning);

  .form-control-warning {
    background-image: url($form-icon-warning);
  }
289
}
290

291
.has-error {
292
293
294
295
296
  @include form-control-validation(error, $brand-danger);

  .form-control-error {
    background-image: url($form-icon-error);
  }
297
}
298

Mark Otto's avatar
Mark Otto committed
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

// .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);
// }
// .has-error {
//   @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;
//   }
// }
376
377


378
379
// Inline forms
//
380
381
382
383
384
385
// 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).
386
387
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
388
389

.form-inline {
390

391
  // Kick in the inline
392
  @include media-breakpoint-up(sm) {
393
    // Inline-block all the things for "inline"
394
    .form-group {
395
396
397
398
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
399
400
401
402

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

407
408
409
410
411
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
412
413
414
415
416
417
418
419
420
421
422
    .input-group {
      display: inline-table;
      vertical-align: middle;

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

423
424
425
426
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
427

428
429
430
    .control-label {
      margin-bottom: 0;
      vertical-align: middle;
431
432
    }

433
    // Remove default margin on radios/checkboxes that were used for stacking, and
434
    // then undo the floating of radios and checkboxes to match.
435
436
437
438
439
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
440
      vertical-align: middle;
441
442
443
444

      label {
        padding-left: 0;
      }
445
446
447
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
448
      position: relative;
449
450
      margin-left: 0;
    }
451

Mark Otto's avatar
Mark Otto committed
452
    // Re-override the feedback icon.
453
454
455
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
456
  }
457
}