forms.less 10.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;
74
  border: 1px solid @inputBorder;
75
76
  .border-radius(3px);
}
77
78
79
80
.uneditable-textarea {
  width: auto;
  height: auto;
}
81

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

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

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

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

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

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

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

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

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

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

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

166

167

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

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
  padding-left: 18px;
}
176
177
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
178
179
180
181
182
183
184
  float: left;
  margin-left: -18px;
}

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

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

202
203


204
205
206
// FOCUS STATE
// -----------

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


230
231
232
233
234
235
236
237
238
239
240

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

242
// Grid style input sizes
243
244
245
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
246
.uneditable-input {
247
  float: none;
248
249
  margin-left: 0;
}
250
251


252
253
254
255

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

256
#grid > .input (@gridColumnWidth, @gridGutterWidth);
257

258

259

260
261
262

// DISABLED STATE
// --------------
263

264
265
266
267
268
269
270
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
271
  background-color: @inputDisabledBackground;
272
  border-color: #ddd;
273
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
274
275
}

276
277


278

279
280
// FORM FIELD FEEDBACK STATES
// --------------------------
281

282
// Warning
283
.control-group.warning {
284
  .formFieldState(@warningText, @warningText, @warningBackground);
285
286
287
}
// Error
.control-group.error {
288
  .formFieldState(@errorText, @errorText, @errorBackground);
289
290
}
// Success
291
.control-group.success {
292
  .formFieldState(@successText, @successText, @successBackground);
293
}
294

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

308
309
310
311
312
313


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

.form-actions {
314
315
316
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
317
  background-color: @grayLighter;
Jacob Thornton's avatar
Jacob Thornton committed
318
  border-top: 1px solid #ddd;
319
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
320
321
}

322
323
324
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
325
  background-color: @inputBackground;
326
327
328
329
330
331
  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
332
.placeholder(@grayLight);
333
334
335



336
337
338
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
339
340
341
342
343
.help-block,
.help-inline {
  color: @gray; // lighten the text some for contrast
}

344
.help-block {
345
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
346
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
347
}
348

Jacob Thornton's avatar
Jacob Thornton committed
349
.help-inline {
350
  display: inline-block;
351
  .ie7-inline-block();
352
  vertical-align: middle;
353
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
354
}
355

356

357

358
359
// INPUT GROUPS
// ------------
360

Jacob Thornton's avatar
Jacob Thornton committed
361
// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
362
363
.input-prepend,
.input-append {
364
  margin-bottom: 5px;
365
  input,
366
  select,
367
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
368
    .border-radius(0 3px 3px 0);
369
370
371
372
    &:focus {
      position: relative;
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
373
  }
374
375
376
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
377
  .add-on {
378
    display: inline-block;
Jacob Thornton's avatar
Jacob Thornton committed
379
380
    width: auto;
    min-width: 16px;
381
    height: @baseLineHeight;
382
    margin-right: -1px;
383
    padding: 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
384
    font-weight: normal;
385
    line-height: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
386
    text-align: center;
387
    text-shadow: 0 1px 0 @white;
388
    vertical-align: middle;
389
    background-color: @grayLighter;
390
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
391
392
393
    .border-radius(3px 0 0 3px);
  }
  .active {
394
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
395
396
397
    border-color: @green;
  }
}
Mark Otto's avatar
Mark Otto committed
398
.input-append {
399
  input,
400
  select
401
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
402
403
    .border-radius(3px 0 0 3px);
  }
404
  .uneditable-input {
405
    border-left-color: #eee;
406
    border-right-color: #ccc;
407
  }
Jacob Thornton's avatar
Jacob Thornton committed
408
  .add-on {
409
410
    margin-right: 0;
    margin-left: -1px;
411
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
412
413
414
  }
}

415

416

417
418
419
// SEARCH FORM
// -----------

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



429
430
431
432
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
433
434
// -----------------

435
436
437
.form-search,
.form-inline,
.form-horizontal {
438
439
440
  input,
  textarea,
  select,
441
  .help-inline,
442
443
444
445
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
446
447
448
449
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
450
}
451
.form-search label,
452
453
454
455
456
.form-inline label,
.form-search .input-append,
.form-inline .input-append,
.form-search .input-prepend,
.form-inline .input-prepend {
457
458
  display: inline-block;
}
459
460
// Make the prepend and append add-on vertical-align: middle;
.form-search .input-append .add-on,
461
462
.form-search .input-prepend .add-on,
.form-inline .input-append .add-on,
463
464
465
.form-inline .input-prepend .add-on {
  vertical-align: middle;
}
466
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
467
468
.form-search .radio,
.form-search .checkbox,
469
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
470
.form-inline .checkbox {
471
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
472
473
474
  margin-bottom: 0;
  vertical-align: middle;
}
475
476
477
478
479
480
481
482
483
484
// 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;
}

485

486
487
// Margin to space out fieldsets
.control-group {
488
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
489
}
490

491
492
493
494
495
496
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

497
498
499
// Horizontal-specific styles
// --------------------------

500
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
501
  // Increase spacing between groups
502
503
  .control-group {
    margin-bottom: @baseLineHeight;
504
    .clearfix();
505
  }
506
  // Float the labels left
507
  .control-label {
508
    float: left;
509
    width: 140px;
510
511
512
513
514
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
515
    margin-left: 160px;
516
  }
Mark Otto's avatar
Mark Otto committed
517
518
519
520
521
  // 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;
  }
522
523
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
524
    padding-left: 160px;
525
  }
526
}