forms.less 8.75 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
40
41
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

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

50
// Set the height of select and file controls to match text inputs
51
input[type="file"] {
52
  display: block;
Mark Otto's avatar
Mark Otto committed
53
}
54

Mark Otto's avatar
Mark Otto committed
55
// Make multiple select elements height not fixed
56
57
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
58
  height: auto;
Mark Otto's avatar
Mark Otto committed
59
60
}

Chris Rebert's avatar
Chris Rebert committed
61
// Fix optgroup Firefox bug per https://github.com/twbs/bootstrap/issues/7611
62
63
64
65
66
67
select optgroup {
  font-size: inherit;
  font-style: inherit;
  font-family: inherit;
}

68
69
70
71
72
73
// Focus for select, file, radio, and checkbox
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
74

75
76
// Fix for Chrome number input
// Setting certain font-sizes causes the `I` bar to appear on hover of the bottom increment button.
Chris Rebert's avatar
Chris Rebert committed
77
// See https://github.com/twbs/bootstrap/issues/8350 for more.
78
input[type="number"] {
79
  &::-webkit-outer-spin-button,
Chris Rebert's avatar
Chris Rebert committed
80
  &::-webkit-inner-spin-button {
81
82
83
84
    height: auto;
  }
}

85
86
87
88
89
90
91
92
93
// 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;
  vertical-align: middle;
}
94

95

Mark Otto's avatar
Mark Otto committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 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;
125
  color: @input-color;
Mark Otto's avatar
Mark Otto committed
126
127
  vertical-align: middle;
  background-color: @input-bg;
128
  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
129
130
131
132
133
  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");

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

137
138
139
140
141
142
  // Placeholder
  //
  // Placeholder text gets special styles because when browsers invalidate entire
  // lines if it doesn't understand a selector/
  .placeholder();

Mark Otto's avatar
Mark Otto committed
143
  // Disabled and read-only inputs
144
145
146
  // 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-bg-disabled;
  }

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


// 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.
174
175
176

.radio,
.checkbox {
177
  display: block;
Mark Otto's avatar
Mark Otto committed
178
  min-height: @line-height-computed; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
179
180
  margin-top: 10px;
  margin-bottom: 10px;
181
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
182
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
183
184
185
186
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
187
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
188
  }
189
}
190
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
191
192
193
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
194
  float: left;
195
  margin-left: -20px;
196
}
Mark Otto's avatar
Mark Otto committed
197
198
.radio + .radio,
.checkbox + .checkbox {
Mark Otto's avatar
Mark Otto committed
199
  margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
Mark Otto committed
200
}
201

202
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
203
204
.radio-inline,
.checkbox-inline {
205
  display: inline-block;
Mark Otto's avatar
Mark Otto committed
206
  padding-left: 20px;
207
  margin-bottom: 0;
208
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
209
  font-weight: normal;
210
  cursor: pointer;
211
}
Mark Otto's avatar
Mark Otto committed
212
213
214
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
215
  margin-left: 10px; // space out consecutive inline controls
216
217
}

218
// Apply same disabled cursor tweak as for inputs
219
//
220
// Note: Neither radios nor checkboxes can be readonly.
221
222
input[type="radio"],
input[type="checkbox"],
223
224
225
226
227
228
229
230
231
.radio,
.radio-inline,
.checkbox,
.checkbox-inline {
  &[disabled],
  fieldset[disabled] & {
    cursor: not-allowed;
  }
}
232

Mark Otto's avatar
Mark Otto committed
233
// Form control sizing
234
.input-sm {
235
  .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @border-radius-small);
236
237
}

ggam's avatar
ggam committed
238
.input-lg {
239
  .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @border-radius-large);
240
}
241

Mark Otto's avatar
Mark Otto committed
242

Mark Otto's avatar
Mark Otto committed
243
244
245
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
246

247
// Warning
248
.has-warning {
249
  .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
250
251
}
// Error
252
.has-error {
253
  .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
254
255
}
// Success
256
.has-success {
257
  .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
258
}
259
260


261
262
263
264
265
266
267
268
269
270
// 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
271
272
273
274
// 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.
275

276
.help-block {
277
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
278
279
280
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
281
}
282
283
284
285
286



// Inline forms
//
287
288
289
290
291
292
// 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).
293
294
//
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
295
296

.form-inline {
297

298
  // Kick in the inline
299
  @media (min-width: @screen-sm) {
300
301
302
303
304
305
    // Inline-block all the things for "inline"
    .form-group  {
      display: inline-block;
      margin-bottom: 0;
      vertical-align: middle;
    }
306
307
308
309
310

    // In navbar-form, allow folks to *not* use `.form-group`
    .form-control {
      display: inline-block;
    }
311

312
313
314
315
316
    // Override `width: 100%;` when not within a `.form-group`
    select.form-control {
      width: auto;
    }

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    // 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;
    }
    .radio input[type="radio"],
    .checkbox input[type="checkbox"] {
      float: none;
      margin-left: 0;
    }
332
333
334
335
336
337
338
339
340
341
  }
}


// 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 {
342
343
344
345
346
347
348
349
350
351
352
353
354

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

  // Make form groups behave like rows
355
356
357
358
  .form-group {
    .make-row();
  }

359
360
361
362
  .form-control-static {
    padding-top: (@padding-base-vertical + 1);
  }

363
  // Only right align form labels here when the columns stop stacking
Zlatan Vasović's avatar
Zlatan Vasović committed
364
  @media (min-width: @screen-sm-min) {
365
366
367
    .control-label {
      text-align: right;
    }
368
369
  }
}