forms.less 9.77 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
  #font > .sans-serif(@baseFontSize,normal,@baseLineHeight);
46
}
47

48
// Identify controls by their labels
49
label {
50
51
  display: block;
  margin-bottom: 5px;
52
53
  color: @grayDark;
}
54

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

76
77
78
79
80
81
82
// Inputs within a label
label input,
label textarea,
label select {
  display: block;
}

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

98
// Reset the file input to browser defaults
99
input[type="file"] {
100
  width: auto;
101
102
  padding: initial;
  line-height: initial;
103
104
105
  border: initial;
  background-color: @white;
  background-color: initial;
106
107
108
  .box-shadow(none);
}

109
// Help out input buttons
110
111
112
input[type="button"],
input[type="reset"],
input[type="submit"] {
113
114
115
116
  width: auto;
  height: auto;
}

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

125
126
127
128
129
// Reset line-height for IE
input[type="file"] {
  line-height: 18px \9;
}

130
// Chrome on Linux and Mobile Safari need background-color
131
select {
132
133
  width: 220px; // default input width + 10px of padding that doesn't get applied
  background-color: @white;
134
135
}

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

Mark Otto's avatar
Mark Otto committed
142
// Remove shadow from image inputs
143
input[type="image"] {
Mark Otto's avatar
Mark Otto committed
144
145
146
  .box-shadow(none);
}

147
// Make textarea height behave
148
149
150
textarea {
  height: auto;
}
151

152
// Hidden inputs
153
input[type="hidden"] {
154
155
156
  display: none;
}

157

158

159
160
161
162
163
164
165
166
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
  padding-left: 18px;
}
167
168
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
169
170
171
172
173
174
175
  float: left;
  margin-left: -18px;
}

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

179
// Radios and checkboxes on same line
180
// TODO v3: Convert .inline to .control-inline
181
182
183
.radio.inline,
.checkbox.inline {
  display: inline-block;
184
  padding-top: 5px;
185
  margin-bottom: 0;
186
  vertical-align: middle;
187
188
189
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
190
  margin-left: 10px; // space out consecutive inline controls
191
192
}

193
194


195
196
197
// FOCUS STATE
// -----------

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


221
222
223
224
225
226
227
228
229
230
231

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

233
// Grid style input sizes
234
235
236
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
237
.uneditable-input {
238
  float: none;
239
240
  margin-left: 0;
}
241
242


243
244
245
246
247
248

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

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

249

250

251
252
253

// DISABLED STATE
// --------------
254

255
256
257
258
259
260
261
262
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
263
  border-color: #ddd;
264
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
265
266
}

267
268


269

270
271
// FORM FIELD FEEDBACK STATES
// --------------------------
272

273
// Warning
274
.control-group.warning {
275
  .formFieldState(@warningText, @warningText, @warningBackground);
276
277
278
}
// Error
.control-group.error {
279
  .formFieldState(@errorText, @errorText, @errorBackground);
280
281
}
// Success
282
.control-group.success {
283
  .formFieldState(@successText, @successText, @successBackground);
284
}
285

286
287
// HTML5 invalid states
// Shares styles with the .control-group.error above
288
289
290
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
291
292
293
294
295
296
297
298
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));    
  }
}

299
300
301
302
303
304


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

.form-actions {
305
306
307
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
308
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
309
310
311
  border-top: 1px solid #ddd;
}

312
313
314
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
315
  background-color: @white;
316
317
318
319
320
321
  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
322
.placeholder(@grayLight);
323
324
325



326
327
328
// HELP TEXT
// ---------

329
.help-block {
330
331
  margin-top: 5px;
  margin-bottom: 0;
332
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
333
}
334

Jacob Thornton's avatar
Jacob Thornton committed
335
.help-inline {
336
  display: inline-block;
337
  .ie7-inline-block();
338
339
  margin-bottom: 9px;
  vertical-align: middle;
340
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
341
}
342

343

344

345
346
// INPUT GROUPS
// ------------
347

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

417

418

419
420
421
// SEARCH FORM
// -----------

422
.search-query {
423
424
  padding-left: 14px;
  padding-right: 14px;
425
  margin-bottom: 0; // remove the default margin on all inputs
426
427
428
429
430
  .border-radius(14px);
}



431
432
433
434
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
435
436
// -----------------

437
438
439
.form-search,
.form-inline,
.form-horizontal {
440
441
442
  input,
  textarea,
  select,
443
  .help-inline,
444
445
446
447
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
448
449
450
451
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
452
}
453
.form-search label,
454
455
456
457
458
.form-inline label,
.form-search .input-append,
.form-inline .input-append,
.form-search .input-prepend,
.form-inline .input-prepend {
459
460
  display: inline-block;
}
461
462
463
464
465
466
467
// 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;
}
Mark Otto's avatar
Mark Otto committed
468
469
470
471
472
473
474
475
// Inline checkbox/radio labels
.form-search .radio,
.form-inline .radio,
.form-search .checkbox,
.form-inline .checkbox {
  margin-bottom: 0;
  vertical-align: middle;
}
476

477
478
// Margin to space out fieldsets
.control-group {
479
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
480
}
481

482
483
484
485
486
487
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

488
489
490
// Horizontal-specific styles
// --------------------------

491
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
492
  // Increase spacing between groups
493
494
  .control-group {
    margin-bottom: @baseLineHeight;
495
    .clearfix();
496
  }
497
  // Float the labels left
498
  .control-label {
499
    float: left;
500
    width: 140px;
501
502
503
504
505
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
506
    margin-left: 160px;
507
508
509
  }
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
510
    padding-left: 160px;
511
  }
512
}