_forms.scss 10.3 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;
  }

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

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
86
87
88
89
90

//
// 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
}


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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  input[type="month"] {
    &.form-control {
      line-height: $input-height-base;
    }

    &.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 {
Mark Otto's avatar
Mark Otto committed
128
  min-height: $input-height-base;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  // Size it appropriately next to real form controls
  padding-top: ($padding-base-vertical + $border-width);
  padding-bottom: ($padding-base-vertical + $border-width);
  // 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;
  padding: $padding-sm-vertical $padding-sm-horizontal;
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  border-radius: $input-border-radius-sm;
}

.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;
}


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 {
Mark Otto's avatar
Mark Otto committed
276
    padding-right: ($input-height-base * 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;
Mark Otto's avatar
Mark Otto committed
286
287
288
  width: $input-height-base;
  height: $input-height-base;
  line-height: $input-height-base;
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
320
  ~ .form-control-feedback {
    top: ($line-height-computed + 5); // Height of the `label` and its margin
321
  }
322

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


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

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


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

.form-inline {
354

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

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

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

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

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

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

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

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

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

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