forms.less 10.9 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
  #font > .shorthand(@baseFontSize,normal,@baseLineHeight); // Set size, weight, line-height here
}
input,
button,
select,
textarea {
51
  font-family: @baseFontFamily; // 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
  color: @gray;
74
  border: 1px solid @inputBorder;
75
76
  .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
  border: initial;
113
  background-color: @inputBackground;
114
  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
  width: 220px; // default input width + 10px of padding that doesn't get applied
142
  background-color: @inputBackground;
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

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

256
#grid > .input (@gridColumnWidth, @gridGutterWidth);
257

258

259

260
261
262

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

264
265
266
267
268
269
270
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
271
  background-color: @inputDisabledBackground;
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
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
304
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
305
306
307
  }
}

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: @grayLighter;
Jacob Thornton's avatar
Jacob Thornton committed
318
  border-top: 1px solid #ddd;
319
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
320
321
}

322
323
324
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
325
  background-color: @inputBackground;
326
327
328
329
330
331
  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
332
.placeholder(@grayLight);
333
334
335



336
337
338
// HELP TEXT
// ---------

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

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

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

356

357

358
359
// INPUT GROUPS
// ------------
360

Jacob Thornton's avatar
Jacob Thornton committed
361
// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
362
363
.input-prepend,
.input-append {
364
  margin-bottom: 5px;
365
  input,
366
  select,
367
  .uneditable-input {
368
    *margin-left: 0;
Jacob Thornton's avatar
Jacob Thornton committed
369
    .border-radius(0 3px 3px 0);
370
371
372
373
    &:focus {
      position: relative;
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
374
  }
375
376
377
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
378
  .add-on {
379
    display: inline-block;
Jacob Thornton's avatar
Jacob Thornton committed
380
381
    width: auto;
    min-width: 16px;
382
    height: @baseLineHeight;
383
    padding: 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
384
    font-weight: normal;
385
    line-height: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
386
    text-align: center;
387
    text-shadow: 0 1px 0 @white;
388
    vertical-align: middle;
389
    background-color: @grayLighter;
390
    border: 1px solid #ccc;
391
392
393
  }
  .add-on,
  .btn {
Jacob Thornton's avatar
Jacob Thornton committed
394
395
396
    .border-radius(3px 0 0 3px);
  }
  .active {
397
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
398
399
400
    border-color: @green;
  }
}
401
.input-prepend {
402
403
  .add-on,
  .btn {
404
405
406
    margin-right: -1px;
  }
}
Mark Otto's avatar
Mark Otto committed
407
.input-append {
408
  input,
409
  select
410
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
411
412
    .border-radius(3px 0 0 3px);
  }
413
  .uneditable-input {
414
    border-left-color: #eee;
415
    border-right-color: #ccc;
416
  }
417
418
  .add-on,
  .btn {
419
420
421
422
423
424
425
426
427
428
429
    margin-left: -1px;
    .border-radius(0 3px 3px 0);
  }
}
// Remove all border-radius for inputs with both prepend and append
.input-prepend.input-append {
  input,
  select,
  .uneditable-input {
    .border-radius(0);
  }
430
431
  .add-on:first-child,
  .btn:first-child {
432
433
434
    margin-right: -1px;
    .border-radius(3px 0 0 3px);
  }
435
436
  .add-on:last-child,
  .btn:last-child {
437
    margin-left: -1px;
438
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
439
440
441
  }
}

442

443

444
445
446
// SEARCH FORM
// -----------

447
.search-query {
448
449
  padding-left: 14px;
  padding-right: 14px;
450
  margin-bottom: 0; // remove the default margin on all inputs
451
452
453
454
455
  .border-radius(14px);
}



456
457
458
459
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
460
461
// -----------------

462
463
464
.form-search,
.form-inline,
.form-horizontal {
465
466
467
  input,
  textarea,
  select,
468
  .help-inline,
469
470
471
  .uneditable-input,
  .input-prepend,
  .input-append {
472
473
474
    display: inline-block;
    margin-bottom: 0;
  }
475
476
477
478
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
479
}
480
.form-search label,
481
.form-inline label {
482
483
  display: inline-block;
}
484
485
486
487
488
489
// Remove margin for input-prepend/-append
.form-search .input-append,
.form-inline .input-append,
.form-search .input-prepend,
.form-inline .input-prepend {
  margin-bottom: 0;
490
}
491
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
492
493
.form-search .radio,
.form-search .checkbox,
494
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
495
.form-inline .checkbox {
496
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
497
498
499
  margin-bottom: 0;
  vertical-align: middle;
}
500
501
502
503
504
505
506
507
508
509
// 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;
}

510

511
512
// Margin to space out fieldsets
.control-group {
513
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
514
}
515

516
517
518
519
520
521
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

522
523
524
// Horizontal-specific styles
// --------------------------

525
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
526
  // Increase spacing between groups
527
528
  .control-group {
    margin-bottom: @baseLineHeight;
529
    .clearfix();
530
  }
531
  // Float the labels left
532
  .control-label {
533
    float: left;
534
    width: 140px;
535
536
537
538
539
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
540
    margin-left: 160px;
541
542
543
544
    /* Super jank IE7 fix to ensure the inputs in .input-append and input-prepend don't inherit the margin of the parent, in this case .controls */
    *display: inline-block;
    *margin-left: 0;
    *padding-left: 20px;
545
  }
Mark Otto's avatar
Mark Otto committed
546
547
548
549
550
  // 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;
  }
551
552
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
553
    padding-left: 160px;
554
  }
555
}