forms.less 12 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
}

90
// Reset background, border, and box-shadow for textual inputs and textarea
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
106
  background-color: @inputBackground;
107
  border: 1px solid @inputBorder;
108
  .border-radius(@inputBorderRadius);
109
110
111
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
112
}
113

114
// Unused selectors
115
116
input[type="radio"],
input[type="checkbox"] {
117
}
118
119
120
input[type="button"],
input[type="submit"],
input[type="reset"] {
121
}
122
input[type="file"] {
123
}
124
125
input[type="hidden"] {
}
126
input[type="image"] {
127
}
128
input[type="range"] {
129
130
}

131
132
// Make uneditable textareas behave like a textarea
.uneditable-textarea {
133
134
135
136
  width: auto;
  height: auto;
}

137
// Set the height of select and file controls to match text inputs
138
select,
139
input[type="file"] {
Mark Otto's avatar
Mark Otto committed
140
  height: 28px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
141
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
142
  line-height: 28px;
Mark Otto's avatar
Mark Otto committed
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

152

153

154

155
156
157
158
159
160
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
161
  min-height: 18px; // clear the floating input if there is no label text
162
163
  padding-left: 18px;
}
164
165
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
166
167
168
169
170
171
172
  float: left;
  margin-left: -18px;
}

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

176
// Radios and checkboxes on same line
177
// TODO v3: Convert .inline to .control-inline
178
179
180
.radio.inline,
.checkbox.inline {
  display: inline-block;
181
  padding-top: 5px;
182
  margin-bottom: 0;
183
  vertical-align: middle;
184
185
186
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
187
  margin-left: 10px; // space out consecutive inline controls
188
189
}

190
191


192
193
194
// FOCUS STATE
// -----------

195
input:focus,
196
197
textarea:focus {
  border-color: rgba(82,168,236,.8);
Mark Otto's avatar
Mark Otto committed
198
  outline: 0;
199
  outline: thin dotted \9; /* IE6-9 */
Jacob Thornton's avatar
Jacob Thornton committed
200
  .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
201
}
202
input[type="file"]:focus,
203
input[type="radio"]:focus,
204
input[type="checkbox"]:focus,
Mark Otto's avatar
Mark Otto committed
205
select:focus {
Mark Otto's avatar
Mark Otto committed
206
  .tab-focus();
Jacob Thornton's avatar
Jacob Thornton committed
207
  .box-shadow(none); // override for file inputs
Mark Otto's avatar
Mark Otto committed
208
}
209
210


211
212
213
214
215
216
217
218
219
220
221

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

223
// Grid style input sizes
224
225
226
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
227
228
229
230
231
232
.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"] {
233
  float: none;
234
235
  margin-left: 0;
}
236
237


238
239
240
241

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

242
#grid > .input (@gridColumnWidth, @gridGutterWidth);
243

244

245

246
247
248

// DISABLED STATE
// --------------
249

250
251
252
253
254
255
256
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
Jacob Thornton's avatar
Jacob Thornton committed
257
  cursor: not-allowed;
258
  background-color: @inputDisabledBackground;
259
  border-color: #ddd;
Jacob Thornton's avatar
Jacob Thornton committed
260
}
261
262
263
264
265
266
267
// 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
268

269
270


271

272
273
// FORM FIELD FEEDBACK STATES
// --------------------------
274

275
// Warning
276
.control-group.warning {
277
  .formFieldState(@warningText, @warningText, @warningBackground);
278
279
280
}
// Error
.control-group.error {
281
  .formFieldState(@errorText, @errorText, @errorBackground);
282
283
}
// Success
284
.control-group.success {
285
  .formFieldState(@successText, @successText, @successBackground);
286
}
287

288
289
// HTML5 invalid states
// Shares styles with the .control-group.error above
290
291
292
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
293
294
295
296
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
297
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
298
299
300
  }
}

301
302
303
304
305
306


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

.form-actions {
307
308
309
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
310
  background-color: @formActionsBackground;
311
  border-top: 1px solid #e5e5e5;
312
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
313
314
}

315
316
// For text that needs to appear as an input but should not be an input
.uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
317
318
319
  overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  white-space: nowrap;
  cursor: not-allowed;
320
  background-color: @inputBackground;
321
322
323
324
325
  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
326
.placeholder();
327
328
329



330
331
332
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
333
334
335
336
337
.help-block,
.help-inline {
  color: @gray; // lighten the text some for contrast
}

338
.help-block {
339
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
340
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
341
}
342

Jacob Thornton's avatar
Jacob Thornton committed
343
.help-inline {
344
  display: inline-block;
345
  .ie7-inline-block();
346
  vertical-align: middle;
347
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
348
}
349

350

351

352
353
// INPUT GROUPS
// ------------
354

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

443

444

445
446
447
// SEARCH FORM
// -----------

448
.search-query {
449
  padding-right: 14px;
450
  padding-right: 4px \9;
Jacob Thornton's avatar
Jacob Thornton committed
451
452
  padding-left: 14px;
  padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
453
  margin-bottom: 0; // remove the default margin on all inputs
454
455
456
457
458
  .border-radius(14px);
}



459
460
461
462
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
463
464
// -----------------

465
466
467
.form-search,
.form-inline,
.form-horizontal {
468
469
470
  input,
  textarea,
  select,
471
  .help-inline,
472
473
474
  .uneditable-input,
  .input-prepend,
  .input-append {
475
    display: inline-block;
476
    .ie7-inline-block();
477
478
    margin-bottom: 0;
  }
479
480
481
482
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
483
}
484
.form-search label,
485
.form-inline label {
486
487
  display: inline-block;
}
488
489
490
491
492
493
// 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;
494
}
495
// Inline checkbox/radio labels (remove padding on left)
Mark Otto's avatar
Mark Otto committed
496
497
.form-search .radio,
.form-search .checkbox,
498
.form-inline .radio,
Mark Otto's avatar
Mark Otto committed
499
.form-inline .checkbox {
500
  padding-left: 0;
Mark Otto's avatar
Mark Otto committed
501
502
503
  margin-bottom: 0;
  vertical-align: middle;
}
504
505
506
507
508
509
510
// 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
511
  margin-left: 0;
512
513
}

514

515
516
// Margin to space out fieldsets
.control-group {
517
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
518
}
519

520
521
522
523
524
525
// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

526
527
528
// Horizontal-specific styles
// --------------------------

529
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
530
  // Increase spacing between groups
531
532
  .control-group {
    margin-bottom: @baseLineHeight;
533
    .clearfix();
534
  }
535
  // Float the labels left
536
  .control-label {
537
    float: left;
538
    width: 140px;
539
540
541
542
543
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
Jacob Thornton's avatar
Jacob Thornton committed
544
545
    // 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
546
547
    *display: inline-block;
    *padding-left: 20px;
Jacob Thornton's avatar
Jacob Thornton committed
548
549
    margin-left: 160px;
    *margin-left: 0;
550
551
552
    &:first-child {
      *padding-left: 160px;
    }
553
  }
Mark Otto's avatar
Mark Otto committed
554
555
556
557
558
  // 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;
  }
559
560
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
561
    padding-left: 160px;
562
  }
563
}