forms.less 12.4 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 #e5e5e5;
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
62
63
// Form controls
// -------------------------

64
// Shared size and type resets
65
select,
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="color"] {
81
  display: inline-block;
82
  height: @baseLineHeight;
83
  padding: 4px;
84
  margin-bottom: 9px;
85
86
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
87
  color: @gray;
88
89
}

Mark Otto's avatar
Mark Otto committed
90
91
92
93
94
95
96
// Reset appearance properties for textual inputs and textarea
// Declare width for legacy (can't be on input[type=*] selectors or it's too specific)
input,
textarea {
  width: 210px;
}
// Everything else
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="color"] {
Mark Otto's avatar
Mark Otto committed
112
  background-color: @inputBackground;
113
  border: 1px solid @inputBorder;
114
  .border-radius(@inputBorderRadius);
115
116
117
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
118
}
119

Mark Otto's avatar
Mark Otto committed
120
// Position radios and checkboxes better
121
122
input[type="radio"],
input[type="checkbox"] {
Mark Otto's avatar
Mark Otto committed
123
124
125
126
  margin: 3px 0;
  *margin-top: 0; /* IE7 */
  line-height: normal;
  cursor: pointer;
127
}
Mark Otto's avatar
Mark Otto committed
128
129

// Reset width of input buttons, radios, checkboxes
130
input[type="submit"],
Mark Otto's avatar
Mark Otto committed
131
132
133
134
135
input[type="reset"],
input[type="button"],
input[type="radio"],
input[type="checkbox"] {
  width: auto; // Override of generic input selector
136
137
}

138
139
// Make uneditable textareas behave like a textarea
.uneditable-textarea {
140
141
142
143
  width: auto;
  height: auto;
}

144
// Set the height of select and file controls to match text inputs
145
select,
146
input[type="file"] {
Mark Otto's avatar
Mark Otto committed
147
  height: 28px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
148
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
149
  line-height: 28px;
Mark Otto's avatar
Mark Otto committed
150
}
151

Mark Otto's avatar
Mark Otto committed
152
153
154
155
156
157
// Make select elements obey height by applying a border
select {
  width: 220px; // default input width + 10px of padding that doesn't get applied
  border: 1px solid #bbb;
}

Mark Otto's avatar
Mark Otto committed
158
// Make multiple select elements height not fixed
159
160
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
161
  height: auto;
Mark Otto's avatar
Mark Otto committed
162
163
}

Mark Otto's avatar
Mark Otto committed
164

165

166

167

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

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

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

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

203
204


205
206
207
// FOCUS STATE
// -----------

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


224
225
226
227
228
229
230
231
232
233
234

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

236
// Grid style input sizes
237
238
239
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
240
241
242
243
244
245
.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"] {
246
  float: none;
247
248
  margin-left: 0;
}
249
250


251
252
253
254

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

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

257

258

259
260
261

// DISABLED STATE
// --------------
262

263
264
265
266
267
268
269
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
Jacob Thornton's avatar
Jacob Thornton committed
270
  cursor: not-allowed;
271
  background-color: @inputDisabledBackground;
272
  border-color: #ddd;
Jacob Thornton's avatar
Jacob Thornton committed
273
}
274
275
276
277
278
279
280
// 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
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;
324
  border-top: 1px solid #e5e5e5;
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 {
Jacob Thornton's avatar
Jacob Thornton committed
330
331
332
  overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  white-space: nowrap;
  cursor: not-allowed;
333
  background-color: @inputBackground;
334
335
336
337
338
  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
339
.placeholder();
340
341
342



343
344
345
// HELP TEXT
// ---------

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

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

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

363

364

365
366
// INPUT GROUPS
// ------------
367

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

456

457

458
459
460
// SEARCH FORM
// -----------

461
.search-query {
462
  padding-right: 14px;
463
  padding-right: 4px \9;
Jacob Thornton's avatar
Jacob Thornton committed
464
465
  padding-left: 14px;
  padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
466
  margin-bottom: 0; // remove the default margin on all inputs
467
468
469
470
471
  .border-radius(14px);
}



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

// Common properties
476
477
// -----------------

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

527

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

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

539
540
541
// Horizontal-specific styles
// --------------------------

542
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
543
  // Increase spacing between groups
544
545
  .control-group {
    margin-bottom: @baseLineHeight;
546
    .clearfix();
547
  }
548
  // Float the labels left
549
  .control-label {
550
    float: left;
551
    width: 140px;
552
553
554
555
556
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
Jacob Thornton's avatar
Jacob Thornton committed
557
558
    // 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
559
560
    *display: inline-block;
    *padding-left: 20px;
Jacob Thornton's avatar
Jacob Thornton committed
561
562
    margin-left: 160px;
    *margin-left: 0;
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
}