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;
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;
89
  border-radius: 0 e("\0/"); // Nuke border-radius for IE9 only
90
91
}

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

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

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

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

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

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

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

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

145

146

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

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

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

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

184
185


186
187
188
// FOCUS STATE
// -----------

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


211
212
213
214
215
216
217
218
219
220
221

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

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

// This is a duplication of the main grid .columns() mixin, but subtracts 10px to account for input padding and border
.inputColumns(@columnSpan: 1) {
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) - 10;
}
236
237
input,
textarea,
238
.uneditable-input {
239
  // Default columns
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  &.span1     { .inputColumns(1); }
  &.span2     { .inputColumns(2); }
  &.span3     { .inputColumns(3); }
  &.span4     { .inputColumns(4); }
  &.span5     { .inputColumns(5); }
  &.span6     { .inputColumns(6); }
  &.span7     { .inputColumns(7); }
  &.span8     { .inputColumns(8); }
  &.span9     { .inputColumns(9); }
  &.span10    { .inputColumns(10); }
  &.span11    { .inputColumns(11); }
  &.span12    { .inputColumns(12); }
}

.selectColumns(@columnSpan: 1) {
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) + 10;
}
select {
  &.span1     { .selectColumns(1); }
  &.span2     { .selectColumns(2); }
  &.span3     { .selectColumns(3); }
  &.span4     { .selectColumns(4); }
  &.span5     { .selectColumns(5); }
  &.span6     { .selectColumns(6); }
  &.span7     { .selectColumns(7); }
  &.span8     { .selectColumns(8); }
  &.span9     { .selectColumns(9); }
  &.span10    { .selectColumns(10); }
  &.span11    { .selectColumns(11); }
  &.span12    { .selectColumns(12); }
270
271
}

272

273
274
275

// DISABLED STATE
// --------------
276

277
278
279
280
281
282
283
284
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
285
  border-color: #ddd;
286
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
287
288
}

289
290


291

292
293
// FORM FIELD FEEDBACK STATES
// --------------------------
294

295
296
297
// Mixin for form field states
.formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  // Set the text color
298
  > label,
299
300
301
  .help-block,
  .help-inline {
    color: @textColor;
302
  }
303
  // Style inputs accordingly
304
  input,
305
  select,
306
307
308
  textarea {
    color: @textColor;
    border-color: @borderColor;
309
    &:focus {
310
      border-color: darken(@borderColor, 10%);
Mark Otto's avatar
Mark Otto committed
311
      .box-shadow(0 0 6px lighten(@borderColor, 20%));
312
313
    }
  }
314
315
316
317
318
319
  // 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;
320
321
  }
}
322
// Warning
323
.control-group.warning {
324
  .formFieldState(@warningText, @warningText, @warningBackground);
325
326
327
}
// Error
.control-group.error {
328
  .formFieldState(@errorText, @errorText, @errorBackground);
329
330
}
// Success
331
.control-group.success {
332
  .formFieldState(@successText, @successText, @successBackground);
333
}
334

335
336
// HTML5 invalid states
// Shares styles with the .control-group.error above
337
338
339
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
340
341
342
343
344
345
346
347
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));    
  }
}

348
349
350
351
352
353


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

.form-actions {
354
355
356
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
357
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
358
359
360
  border-top: 1px solid #ddd;
}

361
362
363
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
364
  background-color: @white;
365
366
367
368
369
370
  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
371
.placeholder(@grayLight);
372
373
374



375
376
377
// HELP TEXT
// ---------

378
.help-block {
379
380
  margin-top: 5px;
  margin-bottom: 0;
381
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
382
}
383

Jacob Thornton's avatar
Jacob Thornton committed
384
.help-inline {
385
  display: inline-block;
386
  .ie7-inline-block();
387
388
  margin-bottom: 9px;
  vertical-align: middle;
389
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
390
}
391

392

393

394
395
// INPUT GROUPS
// ------------
396

Jacob Thornton's avatar
Jacob Thornton committed
397
// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
398
399
.input-prepend,
.input-append {
400
  margin-bottom: 5px;
401
  .clearfix(); // Clear the float to prevent wrapping
402
403
  input,
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
404
    .border-radius(0 3px 3px 0);
405
406
407
408
    &:focus {
      position: relative;
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
409
  }
410
411
412
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
413
414
415
416
417
  .add-on {
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
418
    height: @baseLineHeight;
419
    margin-right: -1px;
420
    padding: 4px 4px 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
421
    font-weight: normal;
422
    line-height: @baseLineHeight;
423
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
424
    text-align: center;
425
    text-shadow: 0 1px 0 @white;
426
427
    background-color: #f5f5f5;
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
428
429
430
    .border-radius(3px 0 0 3px);
  }
  .active {
431
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
432
433
434
    border-color: @green;
  }
}
435
.input-prepend {
Jacob Thornton's avatar
Jacob Thornton committed
436
437
438
439
  .add-on {
    *margin-top: 1px; /* IE6-7 */
  }
}
Mark Otto's avatar
Mark Otto committed
440
.input-append {
441
442
  input,
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
443
444
445
    float: left;
    .border-radius(3px 0 0 3px);
  }
446
447
448
  .uneditable-input {
    border-right-color: #ccc;    
  }
Jacob Thornton's avatar
Jacob Thornton committed
449
  .add-on {
450
451
    margin-right: 0;
    margin-left: -1px;
452
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
453
  }
454
455
456
457
458
459
460
461
462
  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
463
464
}

465

466

467
468
469
// SEARCH FORM
// -----------

470
.search-query {
471
472
  padding-left: 14px;
  padding-right: 14px;
473
  margin-bottom: 0; // remove the default margin on all inputs
474
475
476
477
478
  .border-radius(14px);
}



479
480
481
482
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
483
484
// -----------------

485
486
487
.form-search,
.form-inline,
.form-horizontal {
488
489
490
  input,
  textarea,
  select,
491
  .help-inline,
492
493
494
495
496
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
}
497
498
.form-search label,
.form-inline label {
499
500
  display: inline-block;
}
501

502
503
// Margin to space out fieldsets
.control-group {
504
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
505
}
506

507
508
509
// Horizontal-specific styles
// --------------------------

510
.form-horizontal {
511
512
  // Legend collapses margin, so we're relegated to padding
  legend + .control-group {
Mark Otto's avatar
Mark Otto committed
513
514
    margin-top: @baseLineHeight;
    -webkit-margin-top-collapse: separate;
515
  }
Mark Otto's avatar
Mark Otto committed
516
  // Increase spacing between groups
517
518
  .control-group {
    margin-bottom: @baseLineHeight;
519
    .clearfix();
520
  }
521
522
523
  // Float the labels left
  .control-group > label {
    float: left;
524
    width: 140px;
525
526
527
528
529
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
530
    margin-left: 160px;
531
532
533
  }
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
534
    padding-left: 160px;
535
  }
536
}