forms.less 14.2 KB
Newer Older
1
2
3
//
// Forms
// --------------------------------------------------
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
  margin-bottom: @baseLineHeight;
26
27
  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

60
61
62
// Form controls
// -------------------------

63
// Shared size and type resets
64
select,
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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"],
79
80
input[type="color"],
.uneditable-input {
81
  display: inline-block;
82
  height: @baseLineHeight;
83
  padding: 4px 6px;
84
  margin-bottom: 9px;
85
86
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
87
  color: @gray;
Mark Otto's avatar
Mark Otto committed
88
  .border-radius(@inputBorderRadius);
89
90
}

Mark Otto's avatar
Mark Otto committed
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;
}
97
98
99
100
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
101
// Everything else
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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"],
116
117
input[type="color"],
.uneditable-input {
Mark Otto's avatar
Mark Otto committed
118
  background-color: @inputBackground;
119
  border: 1px solid @inputBorder;
120
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
121
  .transition(~"border linear .2s, box-shadow linear .2s");
122
123
124
125
126
127
128
129

  // Focus state
  &:focus {
    border-color: rgba(82,168,236,.8);
    outline: 0;
    outline: thin dotted \9; /* IE6-9 */
    .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
  }
130
}
131

Mark Otto's avatar
Mark Otto committed
132
// Position radios and checkboxes better
133
134
input[type="radio"],
input[type="checkbox"] {
135
  margin: 4px 0 0;
Mark Otto's avatar
Mark Otto committed
136
  *margin-top: 0; /* IE7 */
137
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
138
139
  line-height: normal;
  cursor: pointer;
140
}
Mark Otto's avatar
Mark Otto committed
141

142
// Reset width of input images, buttons, radios, checkboxes
143
input[type="file"],
144
input[type="image"],
145
input[type="submit"],
Mark Otto's avatar
Mark Otto committed
146
147
148
149
150
input[type="reset"],
input[type="button"],
input[type="radio"],
input[type="checkbox"] {
  width: auto; // Override of generic input selector
151
152
}

153
// Set the height of select and file controls to match text inputs
154
select,
155
input[type="file"] {
156
  height: 30px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
157
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
158
  line-height: 30px;
Mark Otto's avatar
Mark Otto committed
159
}
160

Mark Otto's avatar
Mark Otto committed
161
162
163
164
// 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;
165
  background-color: @inputBackground; // Chrome on Linux and Mobile Safari need background-color
Mark Otto's avatar
Mark Otto committed
166
167
}

Mark Otto's avatar
Mark Otto committed
168
// Make multiple select elements height not fixed
169
170
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
171
  height: auto;
Mark Otto's avatar
Mark Otto committed
172
173
}

174
175
176
177
178
179
180
// Focus for select, file, radio, and checkbox
select:focus,
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
181

182

Mark Otto's avatar
Mark Otto committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Uneditable inputs
// -------------------------

// Make uneditable inputs look inactive
.uneditable-input,
.uneditable-textarea {
  color: @grayLight;
  background-color: darken(@inputBackground, 1%);
  border-color: @inputBorder;
  .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  cursor: not-allowed;
}

// For text that needs to appear as an input but should not be an input
.uneditable-input {
  overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  white-space: nowrap;
}

// Make uneditable textareas behave like a textarea
.uneditable-textarea {
  width: auto;
  height: auto;
}


// Placeholder
// -------------------------

212
// Placeholder text gets special styles because when browsers invalidate entire lines if it doesn’t understand a selector
Mark Otto's avatar
Mark Otto committed
213
214
215
216
217
input,
textarea {
  .placeholder();
}

218

219
220
221
222
223
224
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
225
  min-height: 18px; // clear the floating input if there is no label text
226
227
  padding-left: 18px;
}
228
229
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
230
231
232
233
234
235
236
  float: left;
  margin-left: -18px;
}

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

240
// Radios and checkboxes on same line
241
// TODO v3: Convert .inline to .control-inline
242
243
244
.radio.inline,
.checkbox.inline {
  display: inline-block;
245
  padding-top: 5px;
246
  margin-bottom: 0;
247
  vertical-align: middle;
248
249
250
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
251
  margin-left: 10px; // space out consecutive inline controls
252
253
}

254
255


256
257
258
259
260
261
262
263
264
265
// 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; }
266

267
// Grid style input sizes
268
269
270
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
271
272
273
274
275
276
.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"] {
277
  float: none;
278
279
  margin-left: 0;
}
280
281
282
283
284
// Ensure input-prepend/append never wraps
.input-append input[class*="span"],
.input-append .uneditable-input[class*="span"],
.input-prepend input[class*="span"],
.input-prepend .uneditable-input[class*="span"],
285
286
287
288
.row-fluid input[class*="span"],
.row-fluid select[class*="span"],
.row-fluid textarea[class*="span"],
.row-fluid .uneditable-input[class*="span"],
289
290
291
292
.row-fluid .input-prepend [class*="span"],
.row-fluid .input-append [class*="span"] {
  display: inline-block;
}
293
294


295
296
297
298

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

299
// Grid sizes
300
#grid > .input(@gridColumnWidth, @gridGutterWidth);
301

302
303
304
305
306
307
308
309
310
// Control row for multiple inputs per line
.controls-row {
  .clearfix(); // Clear the float from controls
}
.controls-row [class*="span"] {
  float: left; // Float to collapse white-space for proper grid alignment
}


311

312
313
314

// DISABLED STATE
// --------------
315

316
317
318
319
320
321
322
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
Jacob Thornton's avatar
Jacob Thornton committed
323
  cursor: not-allowed;
324
  background-color: @inputDisabledBackground;
Jacob Thornton's avatar
Jacob Thornton committed
325
}
326
327
328
329
330
331
332
// 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
333

334
335


336

337
338
// FORM FIELD FEEDBACK STATES
// --------------------------
339

340
// Warning
341
.control-group.warning {
342
  .formFieldState(@warningText, @warningText, @warningBackground);
343
344
345
}
// Error
.control-group.error {
346
  .formFieldState(@errorText, @errorText, @errorBackground);
347
348
}
// Success
349
.control-group.success {
350
  .formFieldState(@successText, @successText, @successBackground);
351
}
352
353
354
355
// Success
.control-group.info {
  .formFieldState(@infoText, @infoText, @infoBackground);
}
356

357
358
// HTML5 invalid states
// Shares styles with the .control-group.error above
359
360
361
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
362
363
364
365
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
366
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
367
368
369
  }
}

370
371
372
373
374
375


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

.form-actions {
376
377
378
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
379
  background-color: @formActionsBackground;
380
  border-top: 1px solid #e5e5e5;
381
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
382
383
}

384
385


386
387
388
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
389
390
.help-block,
.help-inline {
391
  color: lighten(@textColor, 15%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
392
393
}

394
.help-block {
395
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
396
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
397
}
398

Jacob Thornton's avatar
Jacob Thornton committed
399
.help-inline {
400
  display: inline-block;
401
  .ie7-inline-block();
402
  vertical-align: middle;
403
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
404
}
405

406

407

408
409
// INPUT GROUPS
// ------------
410

Jacob Thornton's avatar
Jacob Thornton committed
411
// Allow us to put symbols and text within the input field for a cleaner look
412
413
.input-append,
.input-prepend {
414
  margin-bottom: 5px;
415
  font-size: 0;
416
  white-space: nowrap; // Prevent span and input from separating
Mark Otto's avatar
Mark Otto committed
417

418
  input,
419
  select,
420
  .uneditable-input {
421
    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
422
    margin-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
423
    *margin-left: 0;
424
    font-size: @baseFontSize;
425
    vertical-align: top;
426
    .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
427
    // Make input on top when focused so blue border and shadow always show
428
429
430
    &:focus {
      z-index: 2;
    }
Jacob Thornton's avatar
Jacob Thornton committed
431
432
  }
  .add-on {
433
    display: inline-block;
Jacob Thornton's avatar
Jacob Thornton committed
434
    width: auto;
435
    height: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
436
    min-width: 16px;
437
    padding: 4px 5px;
438
    font-size: @baseFontSize;
Jacob Thornton's avatar
Jacob Thornton committed
439
    font-weight: normal;
440
    line-height: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
441
    text-align: center;
442
    text-shadow: 0 1px 0 @white;
443
    background-color: @grayLighter;
444
    border: 1px solid #ccc;
445
446
447
  }
  .add-on,
  .btn {
448
    vertical-align: top;
449
    .border-radius(0);
Jacob Thornton's avatar
Jacob Thornton committed
450
451
  }
  .active {
452
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
453
454
455
    border-color: @green;
  }
}
456
.input-prepend {
457
458
  .add-on,
  .btn {
459
460
    margin-right: -1px;
  }
461
462
  .add-on:first-child,
  .btn:first-child {
463
    .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
464
  }
465
}
Mark Otto's avatar
Mark Otto committed
466
.input-append {
467
  input,
468
  select,
469
  .uneditable-input {
470
    .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
Jacob Thornton's avatar
Jacob Thornton committed
471
  }
472
473
474
475
  .add-on,
  .btn {
    margin-left: -1px;
  }
476
477
  .add-on:last-child,
  .btn:last-child {
478
    .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
479
480
481
482
483
484
485
486
487
  }
}
// Remove all border-radius for inputs with both prepend and append
.input-prepend.input-append {
  input,
  select,
  .uneditable-input {
    .border-radius(0);
  }
488
489
  .add-on:first-child,
  .btn:first-child {
490
    margin-right: -1px;
491
    .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
492
  }
493
494
  .add-on:last-child,
  .btn:last-child {
495
    margin-left: -1px;
496
    .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
Jacob Thornton's avatar
Jacob Thornton committed
497
498
499
  }
}

500

501

502
503
504
// SEARCH FORM
// -----------

505
input.search-query {
506
  padding-right: 14px;
507
  padding-right: 4px \9;
Jacob Thornton's avatar
Jacob Thornton committed
508
509
  padding-left: 14px;
  padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
510
  margin-bottom: 0; // Remove the default margin on all inputs
Mark Otto's avatar
Mark Otto committed
511
  .border-radius(15px);
512
513
}

514
515
516
517
518
519
/* Allow for input prepend/append in search forms */
.form-search .input-append .search-query,
.form-search .input-prepend .search-query {
  .border-radius(0); // Override due to specificity
}
.form-search .input-append .search-query {
Mark Otto's avatar
Mark Otto committed
520
  .border-radius(14px 0 0 14px);
521
522
}
.form-search .input-append .btn {
Mark Otto's avatar
Mark Otto committed
523
  .border-radius(0 14px 14px 0);
524
525
}
.form-search .input-prepend .search-query {
Mark Otto's avatar
Mark Otto committed
526
  .border-radius(0 14px 14px 0);
527
528
}
.form-search .input-prepend .btn {
Mark Otto's avatar
Mark Otto committed
529
  .border-radius(14px 0 0 14px);
530
531
532
}


533
534


535
536
537
538
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
539
540
// -----------------

541
542
543
.form-search,
.form-inline,
.form-horizontal {
544
545
546
  input,
  textarea,
  select,
547
  .help-inline,
548
549
550
  .uneditable-input,
  .input-prepend,
  .input-append {
551
    display: inline-block;
552
    .ie7-inline-block();
553
    margin-bottom: 0;
554
    vertical-align: middle;
555
  }
556
557
558
559
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
560
}
561
.form-search label,
562
563
564
.form-inline label,
.form-search .btn-group,
.form-inline .btn-group {
565
566
  display: inline-block;
}
567
568
569
570
571
572
// 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;
573
}
574
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
575
576
.form-search .radio,
.form-search .checkbox,
577
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
578
.form-inline .checkbox {
579
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
580
581
582
  margin-bottom: 0;
  vertical-align: middle;
}
583
584
585
586
587
588
589
// 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
590
  margin-left: 0;
591
592
}

593

594
595
// Margin to space out fieldsets
.control-group {
596
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
597
}
598

599
600
601
602
603
604
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

605
606
607
// Horizontal-specific styles
// --------------------------

608
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
609
  // Increase spacing between groups
610
611
  .control-group {
    margin-bottom: @baseLineHeight;
612
    .clearfix();
613
  }
614
  // Float the labels left
615
  .control-label {
616
    float: left;
617
    width: 140px;
618
619
620
621
622
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
Jacob Thornton's avatar
Jacob Thornton committed
623
624
    // 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
625
626
    *display: inline-block;
    *padding-left: 20px;
Jacob Thornton's avatar
Jacob Thornton committed
627
628
    margin-left: 160px;
    *margin-left: 0;
629
630
631
    &:first-child {
      *padding-left: 160px;
    }
632
  }
Mark Otto's avatar
Mark Otto committed
633
634
635
636
637
  // 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;
  }
638
639
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
640
    padding-left: 160px;
641
  }
642
}