forms.less 12.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;
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
46
47
48
49
50
  #font > .shorthand(@baseFontSize,normal,@baseLineHeight); // Set size, weight, line-height here
}
input,
button,
select,
textarea {
51
  font-family: @baseFontFamily; // And only set font-family here for those that need it (note the missing label element)
52
}
53

54
// Identify controls by their labels
55
label {
56
57
  display: block;
  margin-bottom: 5px;
58
59
  color: @grayDark;
}
60

61
// Inputs, Textareas, Selects
62
input,
63
64
65
textarea,
select,
.uneditable-input {
66
  display: inline-block;
67
  width: 210px;
68
  height: @baseLineHeight;
69
  padding: 4px;
70
  margin-bottom: 9px;
71
72
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
73
  color: @gray;
Mark Otto's avatar
Mark Otto committed
74
  background-color: @inputBackground;
75
  border: 1px solid @inputBorder;
76
  .border-radius(@inputBorderRadius);
77
}
78
79
80
81
.uneditable-textarea {
  width: auto;
  height: auto;
}
82

83
84
85
86
87
88
89
// Inputs within a label
label input,
label textarea,
label select {
  display: block;
}

Mark Otto's avatar
Mark Otto committed
90
// Mini reset for unique input types
91
92
93
input[type="image"],
input[type="checkbox"],
input[type="radio"] {
94
95
  width: auto;
  height: auto;
96
  padding: 0;
97
  margin: 3px 0;
98
  *margin-top: 0; /* IE7 */
99
  line-height: normal;
100
  cursor: pointer;
Mark Otto's avatar
Mark Otto committed
101
  .border-radius(0);
102
103
104
105
  border: 0 \9; /* IE9 and down */
}
input[type="image"] {
  border: 0;
106
107
}

108
// Reset the file input to browser defaults
109
input[type="file"] {
110
  width: auto;
111
112
  padding: initial;
  line-height: initial;
113
  border: initial;
114
  background-color: @inputBackground;
115
  background-color: initial;
116
117
118
  .box-shadow(none);
}

119
// Help out input buttons
120
121
122
input[type="button"],
input[type="reset"],
input[type="submit"] {
123
124
125
126
  width: auto;
  height: auto;
}

127
// Set the height of select and file controls to match text inputs
128
select,
129
input[type="file"] {
Mark Otto's avatar
Mark Otto committed
130
  height: 28px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
131
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
132
  line-height: 28px;
Mark Otto's avatar
Mark Otto committed
133
}
134

135
136
137
138
139
// Reset line-height for IE
input[type="file"] {
  line-height: 18px \9;
}

140
// Chrome on Linux and Mobile Safari need background-color
141
select {
142
  width: 220px; // default input width + 10px of padding that doesn't get applied
143
  background-color: @inputBackground;
144
145
}

Mark Otto's avatar
Mark Otto committed
146
// Make multiple select elements height not fixed
147
148
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
149
  height: auto;
Mark Otto's avatar
Mark Otto committed
150
151
}

Mark Otto's avatar
Mark Otto committed
152
// Remove shadow from image inputs
153
input[type="image"] {
Mark Otto's avatar
Mark Otto committed
154
155
156
  .box-shadow(none);
}

157
// Make textarea height behave
158
159
160
textarea {
  height: auto;
}
161

162
// Hidden inputs
163
input[type="hidden"] {
164
165
166
  display: none;
}

167

168

169
170
171
172
173
174
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
175
  overflow: auto; // clear the floating input if there is no label text
176
177
  padding-left: 18px;
}
178
179
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
180
181
182
183
184
185
186
  float: left;
  margin-left: -18px;
}

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

190
// Radios and checkboxes on same line
191
// TODO v3: Convert .inline to .control-inline
192
193
194
.radio.inline,
.checkbox.inline {
  display: inline-block;
195
  padding-top: 5px;
196
  margin-bottom: 0;
197
  vertical-align: middle;
198
199
200
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
201
  margin-left: 10px; // space out consecutive inline controls
202
203
}

204
205


206
207
208
// FOCUS STATE
// -----------

209
input,
210
textarea {
211
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
212
213
214
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
215
input:focus,
216
217
textarea:focus {
  border-color: rgba(82,168,236,.8);
218
  .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
Mark Otto's avatar
Mark Otto committed
219
  outline: 0;
220
  outline: thin dotted \9; /* IE6-9 */
221
}
222
input[type="file"]:focus,
223
input[type="radio"]:focus,
224
input[type="checkbox"]:focus,
Mark Otto's avatar
Mark Otto committed
225
226
select:focus {
  .box-shadow(none); // override for file inputs
Mark Otto's avatar
Mark Otto committed
227
  .tab-focus();
Mark Otto's avatar
Mark Otto committed
228
}
229
230


231
232
233
234
235
236
237
238
239
240
241

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

243
// Grid style input sizes
244
245
246
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
247
248
249
250
251
252
.uneditable-input[class*="span"],
// Redeclare since the fluid row class is more specific
.row-fluid input[class*="span"],
.row-fluid select[class*="span"],
.row-fluid textarea[class*="span"],
.row-fluid .uneditable-input[class*="span"] {
253
  float: none;
254
255
  margin-left: 0;
}
256
257


258
259
260
261

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

262
#grid > .input (@gridColumnWidth, @gridGutterWidth);
263

264

265

266
267
268

// DISABLED STATE
// --------------
269

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

282
283


284

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

288
// Warning
289
.control-group.warning {
290
  .formFieldState(@warningText, @warningText, @warningBackground);
291
292
293
}
// Error
.control-group.error {
294
  .formFieldState(@errorText, @errorText, @errorBackground);
295
296
}
// Success
297
.control-group.success {
298
  .formFieldState(@successText, @successText, @successBackground);
299
}
300

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

314
315
316
317
318
319


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

.form-actions {
320
321
322
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
323
  background-color: @formActionsBackground;
Jacob Thornton's avatar
Jacob Thornton committed
324
  border-top: 1px solid #ddd;
325
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
326
327
}

328
329
// For text that needs to appear as an input but should not be an input
.uneditable-input {
330
  background-color: @inputBackground;
331
332
333
  border-color: #eee;
  .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  cursor: not-allowed;
334
335
336
  // prevent text from wrapping, but still cut it off like an input does
  overflow: hidden;
  white-space: nowrap;
337
338
339
}

// 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
// ---------

Mark Otto's avatar
Mark Otto committed
347
348
349
350
351
.help-block,
.help-inline {
  color: @gray; // lighten the text some for contrast
}

352
.help-block {
353
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
354
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
355
}
356

Jacob Thornton's avatar
Jacob Thornton committed
357
.help-inline {
358
  display: inline-block;
359
  .ie7-inline-block();
360
  vertical-align: middle;
361
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
362
}
363

364

365

366
367
// INPUT GROUPS
// ------------
368

Jacob Thornton's avatar
Jacob Thornton committed
369
// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
370
371
.input-prepend,
.input-append {
372
  margin-bottom: 5px;
373
  input,
374
  select,
375
  .uneditable-input {
376
    position: relative; // placed here by default so that on :focus we can place the input above the .add-on for full border and box-shadow goodness
377
    margin-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
378
    *margin-left: 0;
379
    vertical-align: middle;
380
    .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
381
    // Make input on top when focused so blue border and shadow always show
382
383
384
    &:focus {
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
385
  }
386
387
388
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
389
  .add-on {
390
    display: inline-block;
Jacob Thornton's avatar
Jacob Thornton committed
391
392
    width: auto;
    min-width: 16px;
393
    height: @baseLineHeight;
394
    padding: 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
395
    font-weight: normal;
396
    line-height: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
397
    text-align: center;
398
    text-shadow: 0 1px 0 @white;
399
    vertical-align: middle;
400
    background-color: @grayLighter;
401
    border: 1px solid #ccc;
402
403
404
  }
  .add-on,
  .btn {
405
    margin-left: -1px;
406
    .border-radius(0);
Jacob Thornton's avatar
Jacob Thornton committed
407
408
  }
  .active {
409
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
410
411
412
    border-color: @green;
  }
}
413
.input-prepend {
414
415
  .add-on,
  .btn {
416
417
    margin-right: -1px;
  }
418
419
  .add-on:first-child,
  .btn:first-child {
420
    .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
421
  }
422
}
Mark Otto's avatar
Mark Otto committed
423
.input-append {
424
  input,
425
  select,
426
  .uneditable-input {
427
    .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
Jacob Thornton's avatar
Jacob Thornton committed
428
  }
429
  .uneditable-input {
430
    border-left-color: #eee;
431
    border-right-color: #ccc;
432
  }
433
434
  .add-on:last-child,
  .btn:last-child {
435
    .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
436
437
438
439
440
441
442
443
444
  }
}
// Remove all border-radius for inputs with both prepend and append
.input-prepend.input-append {
  input,
  select,
  .uneditable-input {
    .border-radius(0);
  }
445
446
  .add-on:first-child,
  .btn:first-child {
447
    margin-right: -1px;
448
    .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
449
  }
450
451
  .add-on:last-child,
  .btn:last-child {
452
    margin-left: -1px;
453
    .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
Jacob Thornton's avatar
Jacob Thornton committed
454
455
456
  }
}

457

458

459
460
461
// SEARCH FORM
// -----------

462
.search-query {
463
464
  padding-left: 14px;
  padding-right: 14px;
465
466
  padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
  padding-right: 4px \9;
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
  .uneditable-input,
  .input-prepend,
  .input-append {
489
    display: inline-block;
490
    .ie7-inline-block();
491
492
    margin-bottom: 0;
  }
493
494
495
496
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
497
}
498
.form-search label,
499
.form-inline label {
500
501
  display: inline-block;
}
502
503
504
505
506
507
// Remove margin for input-prepend/-append
.form-search .input-append,
.form-inline .input-append,
.form-search .input-prepend,
.form-inline .input-prepend {
  margin-bottom: 0;
508
}
509
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
510
511
.form-search .radio,
.form-search .checkbox,
512
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
513
.form-inline .checkbox {
514
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
515
516
517
  margin-bottom: 0;
  vertical-align: middle;
}
518
519
520
521
522
523
524
525
526
527
// Remove float and margin, set to inline-block
.form-search .radio input[type="radio"],
.form-search .checkbox input[type="checkbox"],
.form-inline .radio input[type="radio"],
.form-inline .checkbox input[type="checkbox"] {
  float: left;
  margin-left: 0;
  margin-right: 3px;
}

528

529
530
// Margin to space out fieldsets
.control-group {
531
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
532
}
533

534
535
536
537
538
539
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

540
541
542
// Horizontal-specific styles
// --------------------------

543
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
544
  // Increase spacing between groups
545
546
  .control-group {
    margin-bottom: @baseLineHeight;
547
    .clearfix();
548
  }
549
  // Float the labels left
550
  .control-label {
551
    float: left;
552
    width: 140px;
553
554
555
556
557
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
558
    margin-left: 160px;
559
    // Super jank IE7 fix to ensure the inputs in .input-append and input-prepend don't inherit the margin of the parent, in this case .controls
560
561
562
    *display: inline-block;
    *margin-left: 0;
    *padding-left: 20px;
563
564
565
    &:first-child {
      *padding-left: 160px;
    }
566
  }
Mark Otto's avatar
Mark Otto committed
567
568
569
570
571
  // Remove bottom margin on block level help text since that's accounted for on .control-group
  .help-block {
    margin-top: @baseLineHeight / 2;
    margin-bottom: 0;
  }
572
573
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
574
    padding-left: 160px;
575
  }
576
}