forms.less 9.64 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 #e5e5e5;
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
128
  height: @input-height-base; /* In IE7, the height of the select element cannot be changed by height, only font-size. TODO: Check if this is still needed when dropping IE7 support */
  line-height: @input-height-base;
Mark Otto's avatar
Mark Otto committed
129
}
130

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

137
138
139
140
141
142
143
// Fix optgroup Firefox bug per https://github.com/twitter/bootstrap/issues/7611
select optgroup {
  font-size: inherit;
  font-style: inherit;
  font-family: inherit;
}

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

151
152
153
154
// Fix for Chrome number input
// Setting certain font-sizes causes the `I` bar to appear on hover of the bottom increment button.
// See https://github.com/twitter/bootstrap/issues/8350 for more.
input[type="number"] {
155
  &::-webkit-outer-spin-button,
156
157
158
159
160
  &::-webkit-inner-spin-button  {
    height: auto;
  }
}

161

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

165
// 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
166
167
168
169
170
input,
textarea {
  .placeholder();
}

171

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

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

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

219
220


221
222
223
// INPUT SIZES
// -----------

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

Mark Otto's avatar
Mark Otto committed
264

265

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

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




285
286
287
// HELP TEXT
// ---------

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

295

296

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

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
406

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

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


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

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

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