forms.less 9.66 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
// Chrome on Linux and Mobile Safari need background-color
126
select {
127
128
  width: 220px; // default input width + 10px of padding that doesn't get applied
  background-color: @white;
129
130
}

Mark Otto's avatar
Mark Otto committed
131
// Make multiple select elements height not fixed
132
133
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
134
  height: auto;
Mark Otto's avatar
Mark Otto committed
135
136
}

Mark Otto's avatar
Mark Otto committed
137
// Remove shadow from image inputs
138
input[type="image"] {
Mark Otto's avatar
Mark Otto committed
139
140
141
  .box-shadow(none);
}

142
// Make textarea height behave
143
144
145
textarea {
  height: auto;
}
146

147
// Hidden inputs
148
input[type="hidden"] {
149
150
151
  display: none;
}

152

153

154
155
156
157
158
159
160
161
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
  padding-left: 18px;
}
162
163
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
164
165
166
167
168
169
170
  float: left;
  margin-left: -18px;
}

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

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

188
189


190
191
192
// FOCUS STATE
// -----------

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


216
217
218
219
220
221
222
223
224
225
226

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

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


238
239
240
241
242
243

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

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

244

245

246
247
248

// DISABLED STATE
// --------------
249

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

262
263


264

265
266
// FORM FIELD FEEDBACK STATES
// --------------------------
267

268
// Warning
269
.control-group.warning {
270
  .formFieldState(@warningText, @warningText, @warningBackground);
271
272
273
}
// Error
.control-group.error {
274
  .formFieldState(@errorText, @errorText, @errorBackground);
275
276
}
// Success
277
.control-group.success {
278
  .formFieldState(@successText, @successText, @successBackground);
279
}
280

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

294
295
296
297
298
299


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

.form-actions {
300
301
302
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
303
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
304
305
306
  border-top: 1px solid #ddd;
}

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



321
322
323
// HELP TEXT
// ---------

324
.help-block {
325
326
  margin-top: 5px;
  margin-bottom: 0;
327
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
328
}
329

Jacob Thornton's avatar
Jacob Thornton committed
330
.help-inline {
331
  display: inline-block;
332
  .ie7-inline-block();
333
334
  margin-bottom: 9px;
  vertical-align: middle;
335
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
336
}
337

338

339

340
341
// INPUT GROUPS
// ------------
342

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

411

412

413
414
415
// SEARCH FORM
// -----------

416
.search-query {
417
418
  padding-left: 14px;
  padding-right: 14px;
419
  margin-bottom: 0; // remove the default margin on all inputs
420
421
422
423
424
  .border-radius(14px);
}



425
426
427
428
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
429
430
// -----------------

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

471
472
// Margin to space out fieldsets
.control-group {
473
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
474
}
475

476
477
478
479
480
481
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

482
483
484
// Horizontal-specific styles
// --------------------------

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