forms.less 11.2 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;
23
24
25
  margin-bottom: @line-height-base;
  font-size: @font-size-base * 1.5;
  line-height: @line-height-base * 2;
26
  color: @grayDark;
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: inline-block;
58
  .box-sizing(border-box); // Makes inputs behave like true block-level elements
59
  min-height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
60
  padding: 6px 9px;
Mark Otto's avatar
Mark Otto committed
61
  // margin-bottom: @line-height-base / 2;
62
63
  font-size: @font-size-base;
  line-height: @line-height-base;
64
  color: @gray;
65
  vertical-align: middle;
66
67
68
  background-color: @input-background;
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
Mark Otto's avatar
Mark Otto committed
69
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
70
  .transition(~"border linear .2s, box-shadow linear .2s");
71
72
}

Mark Otto's avatar
Mark Otto committed
73
// Reset appearance properties for textual inputs and textarea
Mark Otto's avatar
Mark Otto committed
74
// Can't be on input[type=*] selectors or it's too specific
Mark Otto's avatar
Mark Otto committed
75
input,
Mark Otto's avatar
Mark Otto committed
76
select,
77
textarea {
Mark Otto's avatar
Mark Otto committed
78
  width: 100%;
Mark Otto's avatar
Mark Otto committed
79
}
Mark Otto's avatar
Mark Otto committed
80

81
82
83
84
85
86
87
88
89
90
91
// 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
}

92
93
94
95
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
96

Mark Otto's avatar
Mark Otto committed
97
// Everything else
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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"],
112
input[type="color"] {
113
114
115
116
117
  // Focus state
  &:focus {
    border-color: rgba(82,168,236,.8);
    outline: 0;
    outline: thin dotted \9; /* IE6-9 */
Mark Otto's avatar
Mark Otto committed
118
119
    //.box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
    .box-shadow(0 0 8px rgba(82,168,236,.6));
120
  }
121
}
122

Mark Otto's avatar
Mark Otto committed
123
// Position radios and checkboxes better
124
125
input[type="radio"],
input[type="checkbox"] {
126
  margin: 4px 0 0;
127
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
128
  line-height: normal;
129
}
Mark Otto's avatar
Mark Otto committed
130

131
// Set the height of select and file controls to match text inputs
132
select,
133
input[type="file"] {
134
135
  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
136
}
137

Mark Otto's avatar
Mark Otto committed
138
// Make multiple select elements height not fixed
139
140
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
141
  height: auto;
Mark Otto's avatar
Mark Otto committed
142
143
}

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

152

Mark Otto's avatar
Mark Otto committed
153
154
155
// Placeholder
// -------------------------

156
// 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
157
158
159
160
161
input,
textarea {
  .placeholder();
}

162

163
164
165
166
167
168
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
169
  display: block;
170
  min-height: @line-height-base; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
171
  margin-bottom: @line-height-base / 2;
172
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
173
174
175
176
177
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
  }
178
}
Mark Otto's avatar
Mark Otto committed
179

180
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
181
182
183
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
184
  float: left;
185
  margin-left: -20px;
186
}
Mark Otto's avatar
Mark Otto committed
187
188
189
190
.radio + .radio,
.checkbox + .checkbox {
  margin-top: (@line-height-base / 4) * -1;
}
191
192
193
194

// Move the options list down to align with labels
.controls > .radio:first-child,
.controls > .checkbox:first-child {
195
  padding-top: 5px; // has to be padding because margin collaspes
196
197
}

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

214
215


216
217
218
// INPUT SIZES
// -----------

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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"],
234
input[type="color"] {
235
  &.input-large {
236
    padding: @padding-large;
237
238
    font-size: @font-size-large;
    border-radius: @border-radius-large;
239
240
  }
  &.input-small {
241
    min-height: @input-height-small;
242
243
244
    padding: @padding-small;
    font-size: @font-size-small;
    border-radius: @border-radius-small;
245
246
  }
}
247

Mark Otto's avatar
Mark Otto committed
248
249
250
251
252


// GRID SIZING FOR INPUTS
// ----------------------

253
// Grid style input sizes
254
255
input[class*="span"],
select[class*="span"],
256
textarea[class*="span"] {
Mark Otto's avatar
Mark Otto committed
257
258
259
  float: none;
  margin-left: 0;
  margin-right: 0;
260
}
Mark Otto's avatar
Mark Otto committed
261

262
263
// Ensure input-prepend/append never wraps
.input-append input[class*="span"],
264
.input-prepend input[class*="span"] {
265
266
  display: inline-block;
}
267

268
269
input[class*="span"],
select[class*="span"],
270
textarea[class*="span"] {
271
  height: @input-height-base;
272
}
273

274

275
276
277

// DISABLED STATE
// --------------
278

279
// Disabled and read-only inputs
280
281
282
// 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.
283
284
285
286
287
288
289
290
291
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-background-disabled;
  }
Jacob Thornton's avatar
Jacob Thornton committed
292
}
293
// Explicitly reset the colors here
294
295
296
297
298
299
300
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
301
}
Jacob Thornton's avatar
Jacob Thornton committed
302

303
304


305

306
307
// FORM FIELD FEEDBACK STATES
// --------------------------
308

309
// Warning
310
.has-warning {
Mark Otto's avatar
Mark Otto committed
311
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-background);
312
313
}
// Error
314
.has-error {
Mark Otto's avatar
Mark Otto committed
315
  .formFieldState(@state-error-text, @state-error-text, @state-error-background);
316
317
}
// Success
318
.has-success {
Mark Otto's avatar
Mark Otto committed
319
  .formFieldState(@state-success-text, @state-success-text, @state-success-background);
320
}
321

322
323
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
324
325
326
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
327
328
329
330
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
331
332
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
333
334
335
  }
}

336
337
338
339
340
341


// FORM ACTIONS
// ------------

.form-actions {
342
343
344
  padding: (@line-height-base - 1) 20px @line-height-base;
  margin-top: @line-height-base;
  margin-bottom: @line-height-base;
345
  background-color: @form-actions-background;
346
  border-top: 1px solid #e5e5e5;
Mark Otto's avatar
Mark Otto committed
347
  .clear_float(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
348
349
}

350
351


352
353
354
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
355
356
.help-block,
.help-inline {
Mark Otto's avatar
Mark Otto committed
357
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
358
359
}

360
.help-block {
361
  display: block; // account for any element using help-block
362
  margin-bottom: @line-height-base / 2;
Jacob Thornton's avatar
Jacob Thornton committed
363
}
364

Jacob Thornton's avatar
Jacob Thornton committed
365
.help-inline {
366
367
  display: inline-block;
  vertical-align: middle;
368
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
369
}
370

371

372

Mark Otto's avatar
Mark Otto committed
373
374
// Input groups
// --------------------------------------------------
375

Mark Otto's avatar
Mark Otto committed
376
377
378
379
// Base styles
// -------------------------
.input-group {
  display: table;
380

Mark Otto's avatar
Mark Otto committed
381
382
383
384
  // Undo padding and float of grid classes
  &[class*="span"] {
    float: none;
    padding: 0;
385
  }
386

387
  input,
388
  select {
Mark Otto's avatar
Mark Otto committed
389
    width: 100%;
390
391
  }
}
392

Mark Otto's avatar
Mark Otto committed
393
394
395
396
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
397
.input-group input {
Mark Otto's avatar
Mark Otto committed
398
399
400
  display: table-cell;
  margin: 0;
  border-radius: 0;
401
402
403
404
405
406
  &.input-small {
    border-radius: 0;
  }
  &.input-large {
    border-radius: 0;
  }
Jacob Thornton's avatar
Jacob Thornton committed
407
}
Mark Otto's avatar
Mark Otto committed
408
409
410
411
412
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
413
414
}

Mark Otto's avatar
Mark Otto committed
415
416
417
418
419
420
421
422
423
424
425
426
// Text input groups
// -------------------------
.input-group-addon {
  .box-sizing(border-box);
  padding: 6px 8px;
  font-size: @font-size-base;
  font-weight: normal;
  line-height: @line-height-base;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
  background-color: @grayLighter;
  border: 1px solid #ccc;
427
428
429
430
431
432

	&.input-small {
	  padding: @padding-small;
	  font-size: @font-size-small;
  }
	&.input-large {
433
		padding: @padding-large;
434
435
		font-size: @font-size-large;
	}
436
}
Mark Otto's avatar
Mark Otto committed
437
438
439
440
441

// Reset rounded corners
.input-group input:first-child,
.input-group-addon:first-child {
  .border-left-radius(@border-radius-base);
442
443
444
445
446
447
  &.input-small {
    .border-left-radius(@border-radius-small);
  }
  &.input-large {
    .border-left-radius(@border-radius-large);
  }
448
}
Mark Otto's avatar
Mark Otto committed
449
450
.input-group-addon:first-child {
  border-right: 0;
451
}
Mark Otto's avatar
Mark Otto committed
452
453
454
.input-group input:last-child,
.input-group-addon:last-child {
  .border-right-radius(@border-radius-base);
455
456
457
458
459
460
  &.input-small {
    .border-right-radius(@border-radius-small);
  }
  &.input-large {
    .border-right-radius(@border-radius-large);
  }
461
}
Mark Otto's avatar
Mark Otto committed
462
463
.input-group-addon:last-child {
  border-left: 0;
464
465
}

Mark Otto's avatar
Mark Otto committed
466
467
// Button input groups
// -------------------------
468
469
.input-group-btn {
  position: relative;
Mark Otto's avatar
Mark Otto committed
470
  white-space: nowrap;
471
}
Mark Otto's avatar
Mark Otto committed
472
.input-group-btn > .btn {
473
  position: relative;
Mark Otto's avatar
Mark Otto committed
474
475
476
  float: left; // Collapse white-space
  border-radius: 0;
  + .btn {
477
    margin-left: -1px;
478
  }
479
480
481
482
  // Bring the "active" button to the front
  &:hover,
  &:active {
    z-index: 2;
483
  }
Mark Otto's avatar
Mark Otto committed
484
}
485
486
487
488
489
490
491
492
493

// Prepended buttons
.input-group-btn:first-child {
  // Round the left corners only
  > .btn:first-child,
  > .dropdown-toggle:first-child {
    .border-left-radius(@border-radius-base);
    &.btn-large { .border-left-radius(@border-radius-large); }
    &.btn-small { .border-left-radius(@border-radius-small); }
494
  }
495
496
497
498
499
500
501
502
503
504
}

// Appended buttons
.input-group-btn:last-child {
  // Round the right corners only
  > .btn:last-child,
  > .dropdown-toggle {
    .border-right-radius(@border-radius-base);
    &.btn-large { .border-right-radius(@border-radius-large); }
    &.btn-small { .border-right-radius(@border-radius-small); }
505
  }
506
}
Mark Otto's avatar
Mark Otto committed
507
508
509
510
511
512



// Horizontal forms
// --------------------------------------------------

Mark Otto's avatar
Mark Otto committed
513
514
515
@media screen and (min-width: 768px) {

  .form-horizontal {
516

Mark Otto's avatar
Mark Otto committed
517
518
519
520
521
522
523
524
    // Increase spacing between groups
    .control-group {
      position: relative;
      margin-bottom: @line-height-base;
      .clear_float();

      input,
      select,
525
      textarea {
Mark Otto's avatar
Mark Otto committed
526
527
        margin-bottom: 0;
      }
528
    }
Mark Otto's avatar
Mark Otto committed
529

Mark Otto's avatar
Mark Otto committed
530
531
532
533
534
535
536
    // Float the labels left
    .control-group > .control-label {
      float: left;
      width: @component-offset-horizontal - 20;
      padding-top: 6px;
      text-align: right;
    }
Mark Otto's avatar
Mark Otto committed
537

Mark Otto's avatar
Mark Otto committed
538
539
540
541
    // Move over all input controls and content over
    .control-group > .controls {
      margin-left: @component-offset-horizontal;
    }
Mark Otto's avatar
Mark Otto committed
542

Mark Otto's avatar
Mark Otto committed
543
  }
Mark Otto's avatar
Mark Otto committed
544
}