forms.less 10.5 KB
Newer Older
1
2
3
//
// Forms
// --------------------------------------------------
4

5

Mark Otto's avatar
Mark Otto committed
6
7
8
// Normalize non-controls
//
// Restyle and baseline non-control form elements.
9
10
11
12
13

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
14
}
15

16
17
18
legend {
  display: block;
  width: 100%;
19
  padding: 0;
Mark Otto's avatar
Mark Otto committed
20
  margin-bottom: @line-height-computed;
21
  font-size: (@font-size-base * 1.5);
22
  line-height: inherit;
23
  color: @legend-color;
24
  border: 0;
25
  border-bottom: 1px solid @legend-border-color;
26
}
27

28
label {
29
  display: inline-block;
30
  margin-bottom: 5px;
31
  font-weight: bold;
32
}
33

34

Mark Otto's avatar
Mark Otto committed
35
// Normalize form controls
36
37
38
39
//
// While most of our form styles require extra classes, some basic normalization
// is required to ensure optimum display with or without those classes to better
// address browser inconsistencies.
40

41
42
43
44
45
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

Mark Otto's avatar
Mark Otto committed
46
// Position radios and checkboxes better
47
48
input[type="radio"],
input[type="checkbox"] {
49
  margin: 4px 0 0;
50
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
51
  line-height: normal;
52
}
Mark Otto's avatar
Mark Otto committed
53

54
// Set the height of file controls to match text inputs
55
input[type="file"] {
56
  display: block;
Mark Otto's avatar
Mark Otto committed
57
}
58

59
60
61
62
63
64
// Make range inputs behave like textual form controls
input[type="range"] {
  display: block;
  width: 100%;
}

Mark Otto's avatar
Mark Otto committed
65
// Make multiple select elements height not fixed
66
67
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
68
  height: auto;
Mark Otto's avatar
Mark Otto committed
69
70
}

Chris Rebert's avatar
Chris Rebert committed
71
// Fix optgroup Firefox bug per https://github.com/twbs/bootstrap/issues/7611
72
73
74
75
76
77
select optgroup {
  font-size: inherit;
  font-style: inherit;
  font-family: inherit;
}

78
// Focus for file, radio, and checkbox
79
80
81
82
83
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
84

85
// Fix for Chrome number input
86
87
//
// Setting certain font-sizes causes the `I` bar to appear on hover of the
88
// decrement button. See https://github.com/twbs/bootstrap/issues/8350.
89
input[type="number"] {
90
  &::-webkit-outer-spin-button,
Chris Rebert's avatar
Chris Rebert committed
91
  &::-webkit-inner-spin-button {
92
93
94
95
    height: auto;
  }
}

96
97
98
99
100
101
102
103
// Adjust output element
output {
  display: block;
  padding-top: (@padding-base-vertical + 1);
  font-size: @font-size-base;
  line-height: @line-height-base;
  color: @input-color;
}
104

105

Mark Otto's avatar
Mark Otto committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Common form controls
//
// Shared size and type resets for form controls. Apply `.form-control` to any
// of the following form controls:
//
// select
// textarea
// input[type="text"]
// input[type="password"]
// input[type="datetime"]
// input[type="datetime-local"]
// input[type="date"]
// input[type="month"]
// input[type="time"]
// input[type="week"]
// input[type="number"]
// input[type="email"]
// input[type="url"]
// input[type="search"]
// input[type="tel"]
// input[type="color"]

.form-control {
  display: block;
  width: 100%;
  height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  padding: @padding-base-vertical @padding-base-horizontal;
  font-size: @font-size-base;
  line-height: @line-height-base;
135
  color: @input-color;
Mark Otto's avatar
Mark Otto committed
136
  background-color: @input-bg;
137
  background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214
Mark Otto's avatar
Mark Otto committed
138
139
140
141
142
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s");

143
144
  // Customize the `:focus` state to imitate native WebKit styles.
  .form-control-focus();
Mark Otto's avatar
Mark Otto committed
145

146
147
148
  // Placeholder
  .placeholder();

Mark Otto's avatar
Mark Otto committed
149
  // Disabled and read-only inputs
150
151
152
  // Note: 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.
Mark Otto's avatar
Mark Otto committed
153
154
155
156
157
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-bg-disabled;
158
    opacity: 1; // iOS fix for unreadable disabled content
Mark Otto's avatar
Mark Otto committed
159
160
161
162
163
164
165
166
  }

  // Reset height for `textarea`s
  textarea& {
    height: auto;
  }
}

167
168
169
170
171
172
173
174
// Special styles for iOS date input
//
// In Mobile Safari, date inputs require a pixel line-height that matches the
// given height of the input.
input[type="date"] {
  line-height: @input-height-base;
}

Mark Otto's avatar
Mark Otto committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188

// Form groups
//
// Designed to help with the organization and spacing of vertical forms. For
// horizontal forms, use the predefined grid classes.

.form-group {
  margin-bottom: 15px;
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
189
190
191

.radio,
.checkbox {
192
  display: block;
Mark Otto's avatar
Mark Otto committed
193
  min-height: @line-height-computed; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
194
195
  margin-top: 10px;
  margin-bottom: 10px;
196
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
197
198
199
  label {
    display: inline;
    font-weight: normal;
200
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
201
  }
202
}
203
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
204
205
206
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
207
  float: left;
208
  margin-left: -20px;
209
}
Mark Otto's avatar
Mark Otto committed
210
211
.radio + .radio,
.checkbox + .checkbox {
Mark Otto's avatar
Mark Otto committed
212
  margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
Mark Otto committed
213
}
214

215
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
216
217
.radio-inline,
.checkbox-inline {
218
  display: inline-block;
Mark Otto's avatar
Mark Otto committed
219
  padding-left: 20px;
220
  margin-bottom: 0;
221
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
222
  font-weight: normal;
223
  cursor: pointer;
224
}
Mark Otto's avatar
Mark Otto committed
225
226
227
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
228
  margin-left: 10px; // space out consecutive inline controls
229
230
}

231
// Apply same disabled cursor tweak as for inputs
232
//
233
// Note: Neither radios nor checkboxes can be readonly.
234
235
input[type="radio"],
input[type="checkbox"],
236
237
238
239
240
241
242
243
244
.radio,
.radio-inline,
.checkbox,
.checkbox-inline {
  &[disabled],
  fieldset[disabled] & {
    cursor: not-allowed;
  }
}
245

Mark Otto's avatar
Mark Otto committed
246

Mark Otto's avatar
Mark Otto committed
247
// Form control sizing
Mark Otto's avatar
Mark Otto committed
248
249
250
251
//
// Build on `.form-control` with modifier classes to decrease or increase the
// height and font-size of form controls.

252
.input-sm {
253
  .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @border-radius-small);
254
255
}

ggam's avatar
ggam committed
256
.input-lg {
257
  .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @border-radius-large);
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
268
269
270
271
272
273
274
275
276
.has-feedback {
  // Enable absolute positioning
  position: relative;

  // Ensure icons don't overlap text
  .form-control {
    padding-right: (@input-height-base * 1.25);
  }

  // Feedback icon (requires .glyphicon classes)
  .form-control-feedback {
    position: absolute;
Chris Rebert's avatar
Chris Rebert committed
277
    top: (@line-height-computed + 5); // Height of the `label` and its margin
278
279
280
281
282
283
284
285
286
287
    right: 0;
    display: block;
    width: @input-height-base;
    height: @input-height-base;
    line-height: @input-height-base;
    text-align: center;
  }
}

// Feedback states
288
289
290
.has-success {
  .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
}
291
.has-warning {
292
  .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
293
}
294
.has-error {
295
  .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
296
}
297
298


299
300
301
302
303
304
305
306
307
308
// Static form control text
//
// Apply class to a `p` element to make any string of text align with labels in
// a horizontal form layout.

.form-control-static {
  margin-bottom: 0; // Remove default margin from `p`
}


Mark Otto's avatar
Mark Otto committed
309
310
311
312
// 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.
313

314
.help-block {
315
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
316
317
318
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
319
}
320
321
322
323
324



// Inline forms
//
325
326
327
328
329
330
// 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).
331
332
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
333
334

.form-inline {
335

336
  // Kick in the inline
337
  @media (min-width: @screen-sm-min) {
338
    // Inline-block all the things for "inline"
339
    .form-group {
340
341
342
343
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
344
345
346
347

    // In navbar-form, allow folks to *not* use `.form-group`
    .form-control {
      display: inline-block;
348
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
349
      vertical-align: middle;
350
    }
351

352
353
354
    .control-label {
      margin-bottom: 0;
      vertical-align: middle;
355
356
    }

357
358
359
360
361
362
363
364
365
    // Remove default margin on radios/checkboxes that were used for stacking, and
    // then undo the floating of radios and checkboxes to match (which also avoids
    // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
    .radio,
    .checkbox {
      display: inline-block;
      margin-top: 0;
      margin-bottom: 0;
      padding-left: 0;
366
      vertical-align: middle;
367
368
369
370
371
372
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
      float: none;
      margin-left: 0;
    }
373
374
375
376
377
378
379
380

    // Validation states
    //
    // Reposition the icon because it's now within a grid column and columns have
    // `position: relative;` on them. Also accounts for the grid gutter padding.
    .has-feedback .form-control-feedback {
      top: 0;
    }
381
382
383
384
385
386
387
388
389
390
  }
}


// Horizontal forms
//
// Horizontal forms are built on grid classes and allow you to create forms with
// labels on the left and inputs on the right.

.form-horizontal {
391
392
393
394
395
396
397
398
399
400
401

  // Consistent vertical alignment of labels, radios, and checkboxes
  .control-label,
  .radio,
  .checkbox,
  .radio-inline,
  .checkbox-inline {
    margin-top: 0;
    margin-bottom: 0;
    padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  }
402
403
404
405
  // Account for padding we're adding to ensure the alignment and of help text
  // and other content below items
  .radio,
  .checkbox {
406
    min-height: (@line-height-computed + (@padding-base-vertical + 1));
407
  }
408
409

  // Make form groups behave like rows
410
411
412
413
  .form-group {
    .make-row();
  }

414
415
416
417
  .form-control-static {
    padding-top: (@padding-base-vertical + 1);
  }

418
  // Only right align form labels here when the columns stop stacking
Zlatan Vasović's avatar
Zlatan Vasović committed
419
  @media (min-width: @screen-sm-min) {
420
421
422
    .control-label {
      text-align: right;
    }
423
  }
424
425
426
427
428
429
430
431
432

  // Validation states
  //
  // Reposition the icon because it's now within a grid column and columns have
  // `position: relative;` on them. Also accounts for the grid gutter padding.
  .has-feedback .form-control-feedback {
    top: 0;
    right: (@grid-gutter-width / 2);
  }
433
}