forms.less 10.7 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 e("\0/");
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
173
174
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
175
  margin-left: 10px; // space out consecutive inline controls
176
177
}

178
179


180
181
182
// FOCUS STATE
// -----------

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


205
206
207
208
209
210
211
212
213
214
215

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

217
// Grid style input sizes
218
219
220
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
221
.uneditable-input {
222
  float: none;
223
224
  margin-left: 0;
}
225
226
227
228
229

// 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;
}
230
231
input,
textarea,
232
.uneditable-input {
233
  // Default columns
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
  &.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); }
264
265
}

266

267
268
269

// DISABLED STATE
// --------------
270

271
272
273
274
275
276
277
278
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
279
  border-color: #ddd;
280
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
281
282
}

283
284


285

286
287
// FORM FIELD FEEDBACK STATES
// --------------------------
288

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

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

342
343
344
345
346
347


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

.form-actions {
348
349
350
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
351
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
352
353
354
  border-top: 1px solid #ddd;
}

355
356
357
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
358
  background-color: @white;
359
360
361
362
363
364
  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
365
.placeholder(@grayLight);
366
367
368



369
370
371
// HELP TEXT
// ---------

372
.help-block {
373
374
  margin-top: 5px;
  margin-bottom: 0;
375
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
376
}
377

Jacob Thornton's avatar
Jacob Thornton committed
378
.help-inline {
379
  display: inline-block;
380
  .ie7-inline-block();
381
382
  margin-bottom: 9px;
  vertical-align: middle;
383
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
384
}
385

386

387

388
389
// INPUT GROUPS
// ------------
390

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

459

460

461
462
463
// SEARCH FORM
// -----------

464
.search-query {
465
466
  padding-left: 14px;
  padding-right: 14px;
467
  margin-bottom: 0; // remove the default margin on all inputs
468
469
470
471
472
  .border-radius(14px);
}



473
474
475
476
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
477
478
// -----------------

479
480
481
.form-search,
.form-inline,
.form-horizontal {
482
483
484
  input,
  textarea,
  select,
485
  .help-inline,
486
487
488
489
490
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
}
491
492
.form-search label,
.form-inline label {
493
494
  display: inline-block;
}
495

496
497
// Margin to space out fieldsets
.control-group {
498
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
499
}
500

501
502
503
// Horizontal-specific styles
// --------------------------

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