_forms.scss 11 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;
Chris Rebert's avatar
Chris Rebert committed
18
  // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
19
  @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
  // Make inputs at least the height of their button counterpart (base line-height + padding + border).
Chris Rebert's avatar
Chris Rebert committed
24
  // Only apply the height to textual inputs and some selects.
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
93
//
// Note that as of 8.3, iOS doesn't support `datetime` or `week`.
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;
  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;
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
  &.disabled {
Mark Otto's avatar
Mark Otto committed
237
    cursor: $cursor-disabled;
238
239
240
  }
}
// These classes are used directly on <label>s
241
242
.radio-inline,
.checkbox-inline {
243
  &.disabled {
Mark Otto's avatar
Mark Otto committed
244
    cursor: $cursor-disabled;
245
246
  }
}
247
248
249
// These classes are used on elements with <label> descendants
.radio,
.checkbox {
250
  &.disabled {
251
    label {
Mark Otto's avatar
Mark Otto committed
252
      cursor: $cursor-disabled;
253
254
255
    }
  }
}
256

Mark Otto's avatar
Mark Otto committed
257

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

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

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
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
371
372

// .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;
//   }
// }
373
374


375
376
// Inline forms
//
377
378
379
380
381
382
// 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).
383
//
XhmikosR's avatar
XhmikosR committed
384
// Heads up! This is mixin-ed into `.navbar-form` in _navbar.scss.
385
386

.form-inline {
387

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

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

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

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

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

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

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

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

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

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