forms.less 10.6 KB
Newer Older
1
2
3
// Forms.less
// Base styles for various input types, form layouts, and states
// -------------------------------------------------------------
4

5

6
7
// GENERAL STYLES
// --------------
Jacob Thornton's avatar
Jacob Thornton committed
8

9
// Make all forms have space below them
Jacob Thornton's avatar
Jacob Thornton committed
10
form {
11
12
13
14
15
16
17
  margin: 0 0 @baseLineHeight;
}

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

20
// Groups of fields with labels on top (legends)
21
22
23
legend {
  display: block;
  width: 100%;
24
  padding: 0;
25
26
27
  margin-bottom: @baseLineHeight * 1.5;
  font-size: @baseFontSize * 1.5;
  line-height: @baseLineHeight * 2;
28
  color: @grayDark;
29
  border: 0;
30
  border-bottom: 1px solid #eee;
Mark Otto's avatar
Mark Otto committed
31
32
33
34
35
36

  // Small
  small {
    font-size: @baseLineHeight * .75;
    color: @grayLight;
  }
37
}
38

39
40
41
// Set font for forms
label,
input,
42
button,
43
44
select,
textarea {
45
46
47
48
49
50
51
  #font > .shorthand(@baseFontSize,normal,@baseLineHeight); // Set size, weight, line-height here
}
input,
button,
select,
textarea {
  #font > #family > .sans-serif(); // And only set font-family here for those that need it (note the missing label element)
52
}
53

54
// Identify controls by their labels
55
label {
56
57
  display: block;
  margin-bottom: 5px;
58
59
  color: @grayDark;
}
60

61
// Inputs, Textareas, Selects
62
input,
63
64
65
textarea,
select,
.uneditable-input {
66
  display: inline-block;
67
  width: 210px;
68
  height: @baseLineHeight;
69
  padding: 4px;
70
  margin-bottom: 9px;
71
72
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
73
74
75
76
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
77
78
79
80
.uneditable-textarea {
  width: auto;
  height: auto;
}
81

82
83
84
85
86
87
88
// Inputs within a label
label input,
label textarea,
label select {
  display: block;
}

Mark Otto's avatar
Mark Otto committed
89
// Mini reset for unique input types
90
91
92
input[type="image"],
input[type="checkbox"],
input[type="radio"] {
93
94
  width: auto;
  height: auto;
95
  padding: 0;
96
  margin: 3px 0;
97
  *margin-top: 0; /* IE7 */
98
  line-height: normal;
99
  cursor: pointer;
Mark Otto's avatar
Mark Otto committed
100
  .border-radius(0);
101
102
103
104
  border: 0 \9; /* IE9 and down */
}
input[type="image"] {
  border: 0;
105
106
}

107
// Reset the file input to browser defaults
108
input[type="file"] {
109
  width: auto;
110
111
  padding: initial;
  line-height: initial;
112
113
114
  border: initial;
  background-color: @white;
  background-color: initial;
115
116
117
  .box-shadow(none);
}

118
// Help out input buttons
119
120
121
input[type="button"],
input[type="reset"],
input[type="submit"] {
122
123
124
125
  width: auto;
  height: auto;
}

126
// Set the height of select and file controls to match text inputs
127
select,
128
input[type="file"] {
Mark Otto's avatar
Mark Otto committed
129
  height: 28px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
130
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
131
  line-height: 28px;
Mark Otto's avatar
Mark Otto committed
132
}
133

134
135
136
137
138
// Reset line-height for IE
input[type="file"] {
  line-height: 18px \9;
}

139
// Chrome on Linux and Mobile Safari need background-color
140
select {
141
142
  width: 220px; // default input width + 10px of padding that doesn't get applied
  background-color: @white;
143
144
}

Mark Otto's avatar
Mark Otto committed
145
// Make multiple select elements height not fixed
146
147
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
148
  height: auto;
Mark Otto's avatar
Mark Otto committed
149
150
}

Mark Otto's avatar
Mark Otto committed
151
// Remove shadow from image inputs
152
input[type="image"] {
Mark Otto's avatar
Mark Otto committed
153
154
155
  .box-shadow(none);
}

156
// Make textarea height behave
157
158
159
textarea {
  height: auto;
}
160

161
// Hidden inputs
162
input[type="hidden"] {
163
164
165
  display: none;
}

166

167

168
169
170
171
172
173
174
175
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
  padding-left: 18px;
}
176
177
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
178
179
180
181
182
183
184
  float: left;
  margin-left: -18px;
}

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

188
// Radios and checkboxes on same line
189
// TODO v3: Convert .inline to .control-inline
190
191
192
.radio.inline,
.checkbox.inline {
  display: inline-block;
193
  padding-top: 5px;
194
  margin-bottom: 0;
195
  vertical-align: middle;
196
197
198
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
199
  margin-left: 10px; // space out consecutive inline controls
200
201
}

202
203


204
205
206
// FOCUS STATE
// -----------

207
input,
208
textarea {
209
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
210
211
212
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
213
input:focus,
214
215
textarea:focus {
  border-color: rgba(82,168,236,.8);
216
  @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);
217
  .box-shadow(@shadow);
Mark Otto's avatar
Mark Otto committed
218
  outline: 0;
219
  outline: thin dotted \9; /* IE6-9 */
220
}
221
input[type="file"]:focus,
222
input[type="radio"]:focus,
223
input[type="checkbox"]:focus,
Mark Otto's avatar
Mark Otto committed
224
225
select:focus {
  .box-shadow(none); // override for file inputs
Mark Otto's avatar
Mark Otto committed
226
  .tab-focus();
Mark Otto's avatar
Mark Otto committed
227
}
228
229


230
231
232
233
234
235
236
237
238
239
240

// INPUT SIZES
// -----------

// General classes for quick sizes
.input-mini       { width: 60px; }
.input-small      { width: 90px; }
.input-medium     { width: 150px; }
.input-large      { width: 210px; }
.input-xlarge     { width: 270px; }
.input-xxlarge    { width: 530px; }
241

242
// Grid style input sizes
243
244
245
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
246
.uneditable-input {
247
  float: none;
248
249
  margin-left: 0;
}
250
251


252
253
254
255
256
257

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

#inputGridSystem > .generate(@gridColumns, @gridColumnWidth, @gridGutterWidth);

258

259

260
261
262

// DISABLED STATE
// --------------
263

264
265
266
267
268
269
270
271
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
272
  border-color: #ddd;
273
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
274
275
}

276
277


278

279
280
// FORM FIELD FEEDBACK STATES
// --------------------------
281

282
// Warning
283
.control-group.warning {
284
  .formFieldState(@warningText, @warningText, @warningBackground);
285
286
287
}
// Error
.control-group.error {
288
  .formFieldState(@errorText, @errorText, @errorBackground);
289
290
}
// Success
291
.control-group.success {
292
  .formFieldState(@successText, @successText, @successBackground);
293
}
294

295
296
// HTML5 invalid states
// Shares styles with the .control-group.error above
297
298
299
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
300
301
302
303
304
305
306
307
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));    
  }
}

308
309
310
311
312
313


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

.form-actions {
314
315
316
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
317
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
318
319
320
  border-top: 1px solid #ddd;
}

321
322
323
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
324
  background-color: @white;
325
326
327
328
329
330
  border-color: #eee;
  .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  cursor: not-allowed;
}

// Placeholder text gets special styles; can't be bundled together though for some reason
331
.placeholder(@grayLight);
332
333
334



335
336
337
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
338
339
340
341
342
.help-block,
.help-inline {
  color: @gray; // lighten the text some for contrast
}

343
.help-block {
344
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
345
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
346
}
347

Jacob Thornton's avatar
Jacob Thornton committed
348
.help-inline {
349
  display: inline-block;
350
  .ie7-inline-block();
351
  vertical-align: middle;
352
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
353
}
354

355

356

357
358
// INPUT GROUPS
// ------------
359

Jacob Thornton's avatar
Jacob Thornton committed
360
// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
361
362
.input-prepend,
.input-append {
363
  margin-bottom: 5px;
364
  .clearfix(); // Clear the float to prevent wrapping
365
  input,
366
  select,
367
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
368
    .border-radius(0 3px 3px 0);
369
370
371
372
    &:focus {
      position: relative;
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
373
  }
374
375
376
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
377
378
379
380
381
  .add-on {
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
382
    height: @baseLineHeight;
383
    margin-right: -1px;
384
    padding: 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
385
    font-weight: normal;
386
    line-height: @baseLineHeight;
387
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
388
    text-align: center;
389
    text-shadow: 0 1px 0 @white;
390
391
    background-color: #f5f5f5;
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
392
393
394
    .border-radius(3px 0 0 3px);
  }
  .active {
395
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
396
397
398
    border-color: @green;
  }
}
399
.input-prepend {
Jacob Thornton's avatar
Jacob Thornton committed
400
401
402
403
  .add-on {
    *margin-top: 1px; /* IE6-7 */
  }
}
Mark Otto's avatar
Mark Otto committed
404
.input-append {
405
  input,
406
  select
407
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
408
409
410
    float: left;
    .border-radius(3px 0 0 3px);
  }
411
  .uneditable-input {
412
    border-left-color: #eee;
413
414
    border-right-color: #ccc;    
  }
Jacob Thornton's avatar
Jacob Thornton committed
415
  .add-on {
416
417
    margin-right: 0;
    margin-left: -1px;
418
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
419
  }
420
421
422
423
424
425
426
427
428
  input:first-child {
    // In IE7, having a hasLayout container (from clearfix's zoom:1) can make the first input
    // inherit the sum of its ancestors' margins.
    *margin-left: -160px;

    &+.add-on {
      *margin-left: -21px;
    }
  }
Jacob Thornton's avatar
Jacob Thornton committed
429
430
}

431

432

433
434
435
// SEARCH FORM
// -----------

436
.search-query {
437
438
  padding-left: 14px;
  padding-right: 14px;
439
  margin-bottom: 0; // remove the default margin on all inputs
440
441
442
443
444
  .border-radius(14px);
}



445
446
447
448
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
449
450
// -----------------

451
452
453
.form-search,
.form-inline,
.form-horizontal {
454
455
456
  input,
  textarea,
  select,
457
  .help-inline,
458
459
460
461
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
462
463
464
465
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
466
}
467
.form-search label,
468
469
470
471
472
.form-inline label,
.form-search .input-append,
.form-inline .input-append,
.form-search .input-prepend,
.form-inline .input-prepend {
473
474
  display: inline-block;
}
475
476
// Make the prepend and append add-on vertical-align: middle;
.form-search .input-append .add-on,
477
478
.form-search .input-prepend .add-on,
.form-inline .input-append .add-on,
479
480
481
.form-inline .input-prepend .add-on {
  vertical-align: middle;
}
482
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
483
484
.form-search .radio,
.form-search .checkbox,
485
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
486
.form-inline .checkbox {
487
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
488
489
490
  margin-bottom: 0;
  vertical-align: middle;
}
491
492
493
494
495
496
497
498
499
500
// Remove float and margin, set to inline-block
.form-search .radio input[type="radio"],
.form-search .checkbox input[type="checkbox"],
.form-inline .radio input[type="radio"],
.form-inline .checkbox input[type="checkbox"] {
  float: left;
  margin-left: 0;
  margin-right: 3px;
}

501

502
503
// Margin to space out fieldsets
.control-group {
504
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
505
}
506

507
508
509
510
511
512
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

513
514
515
// Horizontal-specific styles
// --------------------------

516
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
517
  // Increase spacing between groups
518
519
  .control-group {
    margin-bottom: @baseLineHeight;
520
    .clearfix();
521
  }
522
  // Float the labels left
523
  .control-label {
524
    float: left;
525
    width: 140px;
526
527
528
529
530
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
531
    margin-left: 160px;
532
  }
Mark Otto's avatar
Mark Otto committed
533
534
535
536
537
  // Remove bottom margin on block level help text since that's accounted for on .control-group
  .help-block {
    margin-top: @baseLineHeight / 2;
    margin-bottom: 0;
  }
538
539
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
540
    padding-left: 160px;
541
  }
542
}