forms.less 10.1 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;
31
}
32

33
34
35
// Set font for forms
label,
input,
36
button,
37
38
select,
textarea {
39
  #font > .sans-serif(@baseFontSize,normal,@baseLineHeight);
40
}
41

42
// Identify controls by their labels
43
label {
44
45
  display: block;
  margin-bottom: 5px;
46
47
  color: @grayDark;
}
48

49
// Inputs, Textareas, Selects
50
input,
51
52
53
textarea,
select,
.uneditable-input {
54
  display: inline-block;
55
  width: 210px;
56
  height: @baseLineHeight;
57
  padding: 4px;
58
  margin-bottom: 9px;
59
60
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
61
62
63
64
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
65
66
67
68
.uneditable-textarea {
  width: auto;
  height: auto;
}
69

70
71
72
73
74
75
76
// Inputs within a label
label input,
label textarea,
label select {
  display: block;
}

Mark Otto's avatar
Mark Otto committed
77
// Mini reset for unique input types
78
79
80
input[type="image"],
input[type="checkbox"],
input[type="radio"] {
81
82
  width: auto;
  height: auto;
83
  padding: 0;
84
  margin: 3px 0;
85
  *margin-top: 0; /* IE7 */
86
  line-height: normal;
87
  border: 0;
88
  cursor: pointer;
Mark Otto's avatar
Mark Otto committed
89
  .border-radius(0);
90
91
}

92
// Reset the file input to browser defaults
93
input[type="file"] {
94
  width: auto;
95
96
  padding: initial;
  line-height: initial;
97
98
99
  border: initial;
  background-color: @white;
  background-color: initial;
100
101
102
  .box-shadow(none);
}

103
// Help out input buttons
104
105
106
input[type="button"],
input[type="reset"],
input[type="submit"] {
107
108
109
110
  width: auto;
  height: auto;
}

111
// Set the height of select and file controls to match text inputs
112
select,
113
input[type="file"] {
Mark Otto's avatar
Mark Otto committed
114
  height: 28px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
115
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
116
  line-height: 28px;
Mark Otto's avatar
Mark Otto committed
117
}
118

119
// Chrome on Linux and Mobile Safari need background-color
120
select {
121
122
  width: 220px; // default input width + 10px of padding that doesn't get applied
  background-color: @white;
123
124
}

Mark Otto's avatar
Mark Otto committed
125
// Make multiple select elements height not fixed
126
127
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
128
  height: auto;
Mark Otto's avatar
Mark Otto committed
129
130
}

Mark Otto's avatar
Mark Otto committed
131
// Remove shadow from image inputs
132
input[type="image"] {
Mark Otto's avatar
Mark Otto committed
133
134
135
  .box-shadow(none);
}

136
// Make textarea height behave
137
138
139
textarea {
  height: auto;
}
140

141
// Hidden inputs
142
input[type="hidden"] {
143
144
145
  display: none;
}

146

147

148
149
150
151
152
153
154
155
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
  padding-left: 18px;
}
156
157
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
158
159
160
161
162
163
164
  float: left;
  margin-left: -18px;
}

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

168
169
170
171
// Radios and checkboxes on same line
.radio.inline,
.checkbox.inline {
  display: inline-block;
172
  margin-bottom: 0;
173
  vertical-align: middle;
174
175
176
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
177
  margin-left: 10px; // space out consecutive inline controls
178
}
179
180
181
// But don't forget to remove their padding on first-child
.controls > .radio.inline:first-child,
.controls > .checkbox.inline:first-child {
182
  padding-top: 0;
183
}
184

185
186


187
188
189
// FOCUS STATE
// -----------

190
input,
191
textarea {
192
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
193
194
195
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
196
input:focus,
197
198
textarea:focus {
  border-color: rgba(82,168,236,.8);
199
  @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);
200
  .box-shadow(@shadow);
Mark Otto's avatar
Mark Otto committed
201
  outline: 0;
Mark Otto's avatar
Mark Otto committed
202
  outline: thin dotted \9; /* IE6-8 */
203
}
204
205
input[type="file"]:focus,
input[type="checkbox"]:focus,
Mark Otto's avatar
Mark Otto committed
206
207
select:focus {
  .box-shadow(none); // override for file inputs
Mark Otto's avatar
Mark Otto committed
208
  .tab-focus();
Mark Otto's avatar
Mark Otto committed
209
}
210
211


212
213
214
215
216
217
218
219
220
221
222

// 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; }
223

224
// Grid style input sizes
225
226
227
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
228
.uneditable-input {
229
  float: none;
230
231
  margin-left: 0;
}
232
233


234
235
236
237
238
239

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

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

240

241

242
243
244

// DISABLED STATE
// --------------
245

246
247
248
249
250
251
252
253
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
254
  border-color: #ddd;
255
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
256
257
}

258
259


260

261
262
// FORM FIELD FEEDBACK STATES
// --------------------------
263

264
265
266
// Mixin for form field states
.formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  // Set the text color
267
  > label,
268
269
270
  .help-block,
  .help-inline {
    color: @textColor;
271
  }
272
  // Style inputs accordingly
273
  input,
274
  select,
275
276
277
  textarea {
    color: @textColor;
    border-color: @borderColor;
278
    &:focus {
279
      border-color: darken(@borderColor, 10%);
Mark Otto's avatar
Mark Otto committed
280
      .box-shadow(0 0 6px lighten(@borderColor, 20%));
281
282
    }
  }
283
284
285
286
287
288
  // Give a small background color for input-prepend/-append
  .input-prepend .add-on,
  .input-append .add-on {
    color: @textColor;
    background-color: @backgroundColor;
    border-color: @textColor;
289
290
  }
}
291
// Warning
292
.control-group.warning {
293
  .formFieldState(@warningText, @warningText, @warningBackground);
294
295
296
}
// Error
.control-group.error {
297
  .formFieldState(@errorText, @errorText, @errorBackground);
298
299
}
// Success
300
.control-group.success {
301
  .formFieldState(@successText, @successText, @successBackground);
302
}
303

304
305
// HTML5 invalid states
// Shares styles with the .control-group.error above
306
307
308
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
309
310
311
312
313
314
315
316
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));    
  }
}

317
318
319
320
321
322


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

.form-actions {
323
324
325
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
326
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
327
328
329
  border-top: 1px solid #ddd;
}

330
331
332
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
333
  background-color: @white;
334
335
336
337
338
339
  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
340
.placeholder(@grayLight);
341
342
343



344
345
346
// HELP TEXT
// ---------

347
.help-block {
348
349
  margin-top: 5px;
  margin-bottom: 0;
350
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
351
}
352

Jacob Thornton's avatar
Jacob Thornton committed
353
.help-inline {
354
  display: inline-block;
355
  .ie7-inline-block();
356
357
  margin-bottom: 9px;
  vertical-align: middle;
358
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
359
}
360

361

362

363
364
// INPUT GROUPS
// ------------
365

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

434

435

436
437
438
// SEARCH FORM
// -----------

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



448
449
450
451
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
452
453
// -----------------

454
455
456
.form-search,
.form-inline,
.form-horizontal {
457
458
459
  input,
  textarea,
  select,
460
  .help-inline,
461
462
463
464
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
465
466
467
468
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
469
}
470
.form-search label,
471
472
473
474
475
.form-inline label,
.form-search .input-append,
.form-inline .input-append,
.form-search .input-prepend,
.form-inline .input-prepend {
476
477
  display: inline-block;
}
478
479
480
481
482
483
484
// Make the prepend and append add-on vertical-align: middle;
.form-search .input-append .add-on,
.form-inline .input-prepend .add-on,
.form-search .input-append .add-on,
.form-inline .input-prepend .add-on {
  vertical-align: middle;
}
485

486
487
// Margin to space out fieldsets
.control-group {
488
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
489
}
490

491
492
493
// Horizontal-specific styles
// --------------------------

494
.form-horizontal {
495
496
  // Legend collapses margin, so we're relegated to padding
  legend + .control-group {
Mark Otto's avatar
Mark Otto committed
497
498
    margin-top: @baseLineHeight;
    -webkit-margin-top-collapse: separate;
499
  }
Mark Otto's avatar
Mark Otto committed
500
  // Increase spacing between groups
501
502
  .control-group {
    margin-bottom: @baseLineHeight;
503
    .clearfix();
504
  }
505
506
507
  // Float the labels left
  .control-group > label {
    float: left;
508
    width: 140px;
509
510
511
512
513
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
514
    margin-left: 160px;
515
516
517
  }
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
518
    padding-left: 160px;
519
  }
520
}