forms.less 11 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-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
369
    *margin-left: 0;
Jacob Thornton's avatar
Jacob Thornton committed
370
    .border-radius(0 3px 3px 0);
371
372
373
374
    &:focus {
      position: relative;
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
375
  }
376
377
378
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
379
  .add-on {
380
    display: inline-block;
Jacob Thornton's avatar
Jacob Thornton committed
381
382
    width: auto;
    min-width: 16px;
383
    height: @baseLineHeight;
384
    padding: 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
385
    font-weight: normal;
386
    line-height: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
387
    text-align: center;
388
    text-shadow: 0 1px 0 @white;
389
    vertical-align: middle;
390
    background-color: @grayLighter;
391
    border: 1px solid #ccc;
392
393
394
  }
  .add-on,
  .btn {
Jacob Thornton's avatar
Jacob Thornton committed
395
396
397
    .border-radius(3px 0 0 3px);
  }
  .active {
398
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
399
400
401
    border-color: @green;
  }
}
402
.input-prepend {
403
404
  .add-on,
  .btn {
405
406
407
    margin-right: -1px;
  }
}
Mark Otto's avatar
Mark Otto committed
408
.input-append {
409
  input,
410
  select
411
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
412
413
    .border-radius(3px 0 0 3px);
  }
414
  .uneditable-input {
415
    border-left-color: #eee;
416
    border-right-color: #ccc;
417
  }
418
419
  .add-on,
  .btn {
420
421
422
423
424
425
426
427
428
429
430
    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);
  }
431
432
  .add-on:first-child,
  .btn:first-child {
433
434
435
    margin-right: -1px;
    .border-radius(3px 0 0 3px);
  }
436
437
  .add-on:last-child,
  .btn:last-child {
438
    margin-left: -1px;
439
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
440
441
442
  }
}

443

444

445
446
447
// SEARCH FORM
// -----------

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



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

// Common properties
461
462
// -----------------

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

511

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

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

523
524
525
// Horizontal-specific styles
// --------------------------

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