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

5

6
// Non-controls
Mark Otto's avatar
Mark Otto committed
7
// -------------------------
Jacob Thornton's avatar
Jacob Thornton committed
8
9

form {
Mark Otto's avatar
Mark Otto committed
10
  margin: 0;
11
12
13
14
15
16
}

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
17
}
18

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

31
label {
32
  display: inline-block;
33
  margin-bottom: 5px;
34
  font-weight: bold;
35
}
36

37
38
39
// Form controls
// -------------------------

40
// Shared size and type resets
41
select,
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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"],
56
input[type="color"] {
Mark Otto's avatar
Mark Otto committed
57
  display: block;
58
  height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
59
  padding: @padding-base-vertical @padding-base-horizontal;
60
61
  font-size: @font-size-base;
  line-height: @line-height-base;
62
  color: @gray;
63
  vertical-align: middle;
64
  background-color: @input-bg;
65
66
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
Mark Otto's avatar
Mark Otto committed
67
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
68
  .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s");
69
70
71
72

  &:focus {
    border-color: rgba(82,168,236,.8);
    outline: 0;
73
    .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
74
  }
75
76
77
78
79
80
81
82
83
84
85

  // Disabled and read-only inputs
  // Note: HTML5 says that inputs 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.
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-bg-disabled;
  }
86
87
}

Mark Otto's avatar
Mark Otto committed
88
// Reset appearance properties for textual inputs and textarea
Mark Otto's avatar
Mark Otto committed
89
// Can't be on input[type=*] selectors or it's too specific
Mark Otto's avatar
Mark Otto committed
90
input,
Mark Otto's avatar
Mark Otto committed
91
select,
92
textarea {
Mark Otto's avatar
Mark Otto committed
93
  width: 100%;
Mark Otto's avatar
Mark Otto committed
94
}
Mark Otto's avatar
Mark Otto committed
95

96
97
98
99
100
101
102
103
104
105
106
// Reset width of input images, buttons, radios, checkboxes
input[type="file"],
input[type="image"],
input[type="submit"],
input[type="reset"],
input[type="button"],
input[type="radio"],
input[type="checkbox"] {
  width: auto; // Override of generic input selector
}

107
108
109
110
111
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

112
113
114
115
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
116

Mark Otto's avatar
Mark Otto committed
117
// Position radios and checkboxes better
118
119
input[type="radio"],
input[type="checkbox"] {
120
  margin: 4px 0 0;
121
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
122
  line-height: normal;
123
}
Mark Otto's avatar
Mark Otto committed
124

125
// Set the height of select and file controls to match text inputs
126
input[type="file"] {
127
  display: block;
Mark Otto's avatar
Mark Otto committed
128
}
129

Mark Otto's avatar
Mark Otto committed
130
// Make multiple select elements height not fixed
131
132
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
133
  height: auto;
Mark Otto's avatar
Mark Otto committed
134
135
}

Chris Rebert's avatar
Chris Rebert committed
136
// Fix optgroup Firefox bug per https://github.com/twbs/bootstrap/issues/7611
137
138
139
140
141
142
select optgroup {
  font-size: inherit;
  font-style: inherit;
  font-family: inherit;
}

143
144
145
146
147
148
// Focus for select, file, radio, and checkbox
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
149

150
151
// 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
152
// See https://github.com/twbs/bootstrap/issues/8350 for more.
153
input[type="number"] {
154
  &::-webkit-outer-spin-button,
155
156
157
158
159
  &::-webkit-inner-spin-button  {
    height: auto;
  }
}

160

Mark Otto's avatar
Mark Otto committed
161
162
163
// Placeholder
// -------------------------

164
// Placeholder text gets special styles because when browsers invalidate entire lines if it doesn't understand a selector
Mark Otto's avatar
Mark Otto committed
165
166
167
168
169
input,
textarea {
  .placeholder();
}

170

171
172
173
174
175
176
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.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
219


220
221
222
// INPUT SIZES
// -----------

223
select,
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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"],
238
input[type="color"] {
239
  &.input-large {
240
    height: @input-height-large;
241
    padding: @padding-large-vertical @padding-large-horizontal;
242
243
    font-size: @font-size-large;
    border-radius: @border-radius-large;
244
245
  }
  &.input-small {
246
    height: @input-height-small;
247
    padding: @padding-small-vertical @padding-small-horizontal;
248
249
    font-size: @font-size-small;
    border-radius: @border-radius-small;
250
251
  }
}
252
253
254
255
256
257
258
259
260
261
select {
  &.input-large {
    height: @input-height-large;
    line-height: @input-height-large;
  }
  &.input-small {
    height: @input-height-small;
    line-height: @input-height-small;
  }
}
262

Mark Otto's avatar
Mark Otto committed
263

264

265
266
// FORM FIELD FEEDBACK STATES
// --------------------------
267

268
// Warning
269
.has-warning {
270
  .form-field-validation(@state-warning-text, @state-warning-text, @state-warning-bg);
271
272
}
// Error
273
.has-error {
274
  .form-field-validation(@state-danger-text, @state-danger-text, @state-danger-bg);
275
276
}
// Success
277
.has-success {
278
  .form-field-validation(@state-success-text, @state-success-text, @state-success-bg);
279
}
280
281
282
283




284
285
286
// HELP TEXT
// ---------

287
.help-block {
288
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
289
290
291
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
292
}
293

294

295

Mark Otto's avatar
Mark Otto committed
296
297
// Input groups
// --------------------------------------------------
298

Mark Otto's avatar
Mark Otto committed
299
300
301
302
// Base styles
// -------------------------
.input-group {
  display: table;
303
  border-collapse: separate; // prevent input groups from inheriting border styles from table cells when placed within a table
304

Mark Otto's avatar
Mark Otto committed
305
  // Undo padding and float of grid classes
Mark Otto's avatar
Mark Otto committed
306
  &.col {
Mark Otto's avatar
Mark Otto committed
307
    float: none;
Mark Otto's avatar
Mark Otto committed
308
309
    padding-left: 0;
    padding-right: 0;
310
  }
311

312
  input,
313
  select {
Mark Otto's avatar
Mark Otto committed
314
    width: 100%;
Mark Otto's avatar
Mark Otto committed
315
    margin-bottom: 0;
316
317
  }
}
318

Mark Otto's avatar
Mark Otto committed
319
320
321
322
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
323
.input-group input {
Mark Otto's avatar
Mark Otto committed
324
  display: table-cell;
325
326

  &:not(:first-child):not(:last-child) {
327
328
    border-radius: 0;
  }
Jacob Thornton's avatar
Jacob Thornton committed
329
}
Mark Otto's avatar
Mark Otto committed
330
331
332
333
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
334
  white-space: nowrap;
Mark Otto's avatar
Mark Otto committed
335
  vertical-align: middle; // Match the inputs
336
337
}

Mark Otto's avatar
Mark Otto committed
338
339
340
341
// Text input groups
// -------------------------
.input-group-addon {
  .box-sizing(border-box);
342
  padding: @padding-base-vertical @padding-base-horizontal;
Mark Otto's avatar
Mark Otto committed
343
344
345
346
  font-size: @font-size-base;
  font-weight: normal;
  line-height: @line-height-base;
  text-align: center;
347
  background-color: @gray-lighter;
348
  border: 1px solid @input-group-addon-border-color;
349
  border-radius: @border-radius-base;
350

Mark Otto's avatar
Mark Otto committed
351
  &.input-small {
352
    padding: @padding-small-vertical @padding-small-horizontal;
Mark Otto's avatar
Mark Otto committed
353
    font-size: @font-size-small;
354
355
    border-radius: @border-radius-small;
  }
Mark Otto's avatar
Mark Otto committed
356
  &.input-large {
357
    padding: @padding-large-vertical @padding-large-horizontal;
Mark Otto's avatar
Mark Otto committed
358
    font-size: @font-size-large;
359
    border-radius: @border-radius-large;
360
  }
361
}
Mark Otto's avatar
Mark Otto committed
362
363
364

// Reset rounded corners
.input-group input:first-child,
365
.input-group-addon:first-child,
366
367
368
.input-group-btn:first-child > .btn,
.input-group-btn:first-child > .dropdown-toggle,
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle) {
369
  .border-right-radius(0);
370
}
Mark Otto's avatar
Mark Otto committed
371
372
.input-group-addon:first-child {
  border-right: 0;
373
}
Mark Otto's avatar
Mark Otto committed
374
.input-group input:last-child,
375
.input-group-addon:last-child,
376
377
378
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child) {
379
  .border-left-radius(0);
380
}
Mark Otto's avatar
Mark Otto committed
381
382
.input-group-addon:last-child {
  border-left: 0;
383
384
}

Mark Otto's avatar
Mark Otto committed
385
386
// Button input groups
// -------------------------
387
388
.input-group-btn {
  position: relative;
Mark Otto's avatar
Mark Otto committed
389
  white-space: nowrap;
390
}
Mark Otto's avatar
Mark Otto committed
391
.input-group-btn > .btn {
392
  position: relative;
393
  // Jankily prevent input button groups from wrapping
Mark Otto's avatar
Mark Otto committed
394
  + .btn {
395
    margin-left: -4px;
396
  }
397
398
399
400
  // Bring the "active" button to the front
  &:hover,
  &:active {
    z-index: 2;
401
  }
Mark Otto's avatar
Mark Otto committed
402
}
403

Mark Otto's avatar
Mark Otto committed
404

Mark Otto's avatar
Mark Otto committed
405
406
407
408
409
410
411
412
413
414
// Inline forms
// --------------------------------------------------

.form-inline {
  input,
  select,
  textarea,
  .radio,
  .checkbox {
    display: inline-block;
Mark Otto's avatar
Mark Otto committed
415
416
417
418
  }
  .radio,
  .checkbox {
    margin-top: 0;
Mark Otto's avatar
Mark Otto committed
419
420
421
422
423
    margin-bottom: 0;
  }
}


Mark Otto's avatar
Mark Otto committed
424
425
// Horizontal forms
// --------------------------------------------------
Mark Otto's avatar
Mark Otto committed
426
// Horizontal forms are built on grid classes.
Mark Otto's avatar
Mark Otto committed
427

Mark Otto's avatar
Mark Otto committed
428
429
430
431
.form-horizontal {
  .row + .row {
    margin-top: 15px;
  }
432
  .control-label {
Mark Otto's avatar
Mark Otto committed
433
    padding-top: 6px;
434
435
436
  }
}

Chris Rebert's avatar
Chris Rebert committed
437
// Only right align form labels here when the columns stop stacking
Bass Jobsen's avatar
Bass Jobsen committed
438
@media (min-width: @screen-tablet) {
439
  .form-horizontal .control-label {
Mark Otto's avatar
Mark Otto committed
440
    text-align: right;
Mark Otto's avatar
Mark Otto committed
441
  }
Mark Otto's avatar
Mark Otto committed
442
}