_forms.scss 10.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
  // // Make inputs at least the height of their button counterpart (base line-height + padding + border)
14
  // height: $input-height;
15
  padding: $padding-y $padding-x;
Mark Otto's avatar
Mark Otto committed
16
17
18
19
  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;
22
  border: $border-width 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
  // 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.
30
31
32
  // &:not(textarea),
  // &:not(select[size]),
  // &:not(select[multiple]) {
33
  //   height: $input-height;
34
  // }
35

Mark Otto's avatar
Mark Otto committed
36
37
38
  // Unstyle the caret on `<select>`s in IE10+.
  &::-ms-expand {
    background-color: transparent;
Mark Otto's avatar
Mark Otto committed
39
    border: 0;
Mark Otto's avatar
Mark Otto committed
40
41
  }

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
79
80
81
82
83
84
85

//
// Labels
//

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
.form-control-label {
86
  padding: ($padding-y + $border-width) $padding-x;
87
88
89
90
  margin-bottom: 0; // Override the `<label>` default
}


91
// Todo: clear this up
92

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

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

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

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

Mark Otto's avatar
Mark Otto committed
121

122
123
124
125
126
127
// 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 {
128
  min-height: $input-height;
129
  // Size it appropriately next to real form controls
130
131
  padding-top: ($padding-y + $border-width);
  padding-bottom: ($padding-y + $border-width);
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  // 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 {
  height: $input-height-sm;
153
  padding: $padding-sm-y $padding-sm-x;
154
155
156
157
158
159
160
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  border-radius: $input-border-radius-sm;
}

.form-control-lg {
  height: $input-height-lg;
161
  padding: $padding-lg-y $padding-lg-x;
162
163
164
165
166
167
  font-size: $font-size-lg;
  line-height: $line-height-lg;
  border-radius: $input-border-radius-lg;
}


Mark Otto's avatar
Mark Otto committed
168
169
170
171
172
173
// 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
174
  margin-bottom: $form-group-margin-bottom;
Mark Otto's avatar
Mark Otto committed
175
176
177
178
179
180
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
181
182
183

.radio,
.checkbox {
184
  position: relative;
185
  display: block;
186
187
  // margin-top:    ($spacer * .75);
  margin-bottom: ($spacer * .75);
Mark Otto's avatar
Mark Otto committed
188

Mark Otto's avatar
Mark Otto committed
189
  label {
190
    padding-left: 1.25rem;
191
    margin-bottom: 0;
Mark Otto's avatar
Mark Otto committed
192
    font-weight: normal;
193
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
194
195
196
197
198

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

Mark Otto's avatar
Mark Otto committed
211
212
.radio + .radio,
.checkbox + .checkbox {
213
214
  // Move up sibling radios or checkboxes for tighter spacing
  margin-top: -.25rem;
Mark Otto's avatar
Mark Otto committed
215
}
216

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

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

Mark Otto's avatar
Mark Otto committed
265

Mark Otto's avatar
Mark Otto committed
266
267
268
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
269

270
271
272
273
274
275
.has-feedback {
  // Enable absolute positioning
  position: relative;

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

Mark Otto's avatar
Mark Otto committed
305
// Form validation states
306
.has-success {
Mark Otto's avatar
Mark Otto committed
307
  @include form-control-validation($state-success-text, $state-success-text, $state-success-bg);
308
}
309
.has-warning {
Mark Otto's avatar
Mark Otto committed
310
  @include form-control-validation($state-warning-text, $state-warning-text, $state-warning-bg);
311
}
312
.has-error {
Mark Otto's avatar
Mark Otto committed
313
  @include form-control-validation($state-danger-text, $state-danger-text, $state-danger-bg);
314
}
315

316
317
// Reposition feedback icon if input has visible label above
.has-feedback label {
Mark Otto's avatar
Mark Otto committed
318

319
  ~ .form-control-feedback {
Mark Otto's avatar
Mark Otto committed
320
321
    // TODO: redo this since we nuked the `$line-height-computed`
    top: 0; // Height of the `label` and its margin
322
  }
323

324
  &.sr-only ~ .form-control-feedback {
325
    top: 0;
326
  }
327
328
329
}


Mark Otto's avatar
Mark Otto committed
330
331
332
333
// 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.
334

335
.help-block {
336
  display: block; // account for any element using help-block
337
338
  margin-top: .25rem;
  margin-bottom: .75rem;
Mark Otto's avatar
Mark Otto committed
339
  color: lighten($text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
340
}
341
342
343
344


// Inline forms
//
345
346
347
348
349
350
// 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).
351
352
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
353
354

.form-inline {
355

356
  // Kick in the inline
357
  @include media-breakpoint-up(sm) {
358
    // Inline-block all the things for "inline"
359
    .form-group {
360
361
362
363
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
364
365
366
367

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

372
373
374
375
376
    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

Mark Otto's avatar
Mark Otto committed
377
378
379
380
381
382
383
384
385
386
387
    .input-group {
      display: inline-table;
      vertical-align: middle;

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

388
389
390
391
    // Input groups need that 100% width though
    .input-group > .form-control {
      width: 100%;
    }
392

393
394
395
    .control-label {
      margin-bottom: 0;
      vertical-align: middle;
396
397
    }

398
    // Remove default margin on radios/checkboxes that were used for stacking, and
399
    // then undo the floating of radios and checkboxes to match.
400
401
402
403
404
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
405
      vertical-align: middle;
406
407
408
409

      label {
        padding-left: 0;
      }
410
411
412
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
413
      position: relative;
414
415
      margin-left: 0;
    }
416

Mark Otto's avatar
Mark Otto committed
417
    // Re-override the feedback icon.
418
419
420
    .has-feedback .form-control-feedback {
      top: 0;
    }
Mark Otto's avatar
Mark Otto committed
421
  }
422
}