forms.less 12.3 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;
101
  background-color: transparent;
102
  border: 0 \9; /* IE9 and down */
Jacob Thornton's avatar
Jacob Thornton committed
103
  .border-radius(0);
104
105
106
}
input[type="image"] {
  border: 0;
107
108
}

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

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

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

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

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

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

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

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

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

168

169

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

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

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

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

205
206


207
208
209
// FOCUS STATE
// -----------

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


232
233
234
235
236
237
238
239
240
241
242

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

244
// Grid style input sizes
245
246
247
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
248
249
250
251
252
253
.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"] {
254
  float: none;
255
256
  margin-left: 0;
}
257
258


259
260
261
262

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

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

265

266

267
268
269

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

271
272
273
274
275
276
277
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
Jacob Thornton's avatar
Jacob Thornton committed
278
  cursor: not-allowed;
279
  background-color: @inputDisabledBackground;
280
  border-color: #ddd;
Jacob Thornton's avatar
Jacob Thornton committed
281
}
282
283
284
285
286
287
288
// Explicitly reset the colors here
input[type="radio"][disabled],
input[type="checkbox"][disabled],
input[type="radio"][readonly],
input[type="checkbox"][readonly] {
  background-color: transparent;
}
Jacob Thornton's avatar
Jacob Thornton committed
289

290
291


292

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

296
// Warning
297
.control-group.warning {
298
  .formFieldState(@warningText, @warningText, @warningBackground);
299
300
301
}
// Error
.control-group.error {
302
  .formFieldState(@errorText, @errorText, @errorBackground);
303
304
}
// Success
305
.control-group.success {
306
  .formFieldState(@successText, @successText, @successBackground);
307
}
308

309
310
// HTML5 invalid states
// Shares styles with the .control-group.error above
311
312
313
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
314
315
316
317
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
318
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
319
320
321
  }
}

322
323
324
325
326
327


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

.form-actions {
328
329
330
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
331
  background-color: @formActionsBackground;
Jacob Thornton's avatar
Jacob Thornton committed
332
  border-top: 1px solid #ddd;
333
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
334
335
}

336
337
// For text that needs to appear as an input but should not be an input
.uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
338
339
340
  overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  white-space: nowrap;
  cursor: not-allowed;
341
  background-color: @inputBackground;
342
343
344
345
346
  border-color: #eee;
  .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
}

// Placeholder text gets special styles; can't be bundled together though for some reason
347
.placeholder();
348
349
350



351
352
353
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
354
355
356
357
358
.help-block,
.help-inline {
  color: @gray; // lighten the text some for contrast
}

359
.help-block {
360
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
361
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
362
}
363

Jacob Thornton's avatar
Jacob Thornton committed
364
.help-inline {
365
  display: inline-block;
366
  .ie7-inline-block();
367
  vertical-align: middle;
368
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
369
}
370

371

372

373
374
// INPUT GROUPS
// ------------
375

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

464

465

466
467
468
// SEARCH FORM
// -----------

469
.search-query {
470
  padding-right: 14px;
471
  padding-right: 4px \9;
Jacob Thornton's avatar
Jacob Thornton committed
472
473
  padding-left: 14px;
  padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
474
  margin-bottom: 0; // remove the default margin on all inputs
475
476
477
478
479
  .border-radius(14px);
}



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

// Common properties
484
485
// -----------------

486
487
488
.form-search,
.form-inline,
.form-horizontal {
489
490
491
  input,
  textarea,
  select,
492
  .help-inline,
493
494
495
  .uneditable-input,
  .input-prepend,
  .input-append {
496
    display: inline-block;
497
    .ie7-inline-block();
498
499
    margin-bottom: 0;
  }
500
501
502
503
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
504
}
505
.form-search label,
506
.form-inline label {
507
508
  display: inline-block;
}
509
510
511
512
513
514
// 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;
515
}
516
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
517
518
.form-search .radio,
.form-search .checkbox,
519
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
520
.form-inline .checkbox {
521
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
522
523
524
  margin-bottom: 0;
  vertical-align: middle;
}
525
526
527
528
529
530
531
// 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-right: 3px;
Jacob Thornton's avatar
Jacob Thornton committed
532
  margin-left: 0;
533
534
}

535

536
537
// Margin to space out fieldsets
.control-group {
538
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
539
}
540

541
542
543
544
545
546
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

547
548
549
// Horizontal-specific styles
// --------------------------

550
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
551
  // Increase spacing between groups
552
553
  .control-group {
    margin-bottom: @baseLineHeight;
554
    .clearfix();
555
  }
556
  // Float the labels left
557
  .control-label {
558
    float: left;
559
    width: 140px;
560
561
562
563
564
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
Jacob Thornton's avatar
Jacob Thornton committed
565
566
    // 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
567
568
    *display: inline-block;
    *padding-left: 20px;
Jacob Thornton's avatar
Jacob Thornton committed
569
570
    margin-left: 160px;
    *margin-left: 0;
571
572
573
    &:first-child {
      *padding-left: 160px;
    }
574
  }
Mark Otto's avatar
Mark Otto committed
575
576
577
578
579
  // 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;
  }
580
581
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
582
    padding-left: 160px;
583
  }
584
}