_forms.scss 10.9 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,
53
  &[readonly] {
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
  &:disabled {
Mark Otto's avatar
Mark Otto committed
60
    cursor: $cursor-disabled;
61
  }
Mark Otto's avatar
Mark Otto committed
62
}
Mark Otto's avatar
Mark Otto committed
63
64


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

71
72
73
74
75
76
77
78

//
// Labels
//

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


84
// Todo: clear this up
85

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

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

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

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

Mark Otto's avatar
Mark Otto committed
114

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

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


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


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
174
175
176

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

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

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

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

210
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
211
212
.radio-inline,
.checkbox-inline {
213
  position: relative;
214
  display: inline-block;
215
  padding-left: 1.25rem;
216
  margin-bottom: 0;
Mark Otto's avatar
Mark Otto committed
217
  font-weight: normal;
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
262
.form-control-success,
.form-control-warning,
.form-control-error {
263
  padding-right: ($input-padding-x * 3);
264
  background-repeat: no-repeat;
265
266
  background-position: center right ($input-height * .25);
  background-size: ($input-height * .65) ($input-height * .65);
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
274
275

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

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

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

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

  .form-control-error {
    background-image: url($form-icon-error);
  }
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

// .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;
//   }
// }
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
//
XhmikosR's avatar
XhmikosR committed
382
// Heads up! This is mixin-ed into `.navbar-form` in _navbar.scss.
383
384

.form-inline {
385

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

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

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

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

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

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

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

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

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

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