forms.less 10.1 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;
31
  -webkit-margin-collapse: separate;
32
}
33

34
35
36
// Set font for forms
label,
input,
37
button,
38
39
select,
textarea {
40
  #font > .sans-serif(@baseFontSize,normal,@baseLineHeight);
41
}
42

43
// Identify controls by their labels
44
label {
45
46
  display: block;
  margin-bottom: 5px;
47
48
  color: @grayDark;
}
49

50
// Inputs, Textareas, Selects
51
input,
52
53
54
textarea,
select,
.uneditable-input {
55
  display: inline-block;
56
  width: 210px;
57
  height: @baseLineHeight;
58
  padding: 4px;
59
  margin-bottom: 9px;
60
61
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
62
63
64
65
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
66
67
68
69
.uneditable-textarea {
  width: auto;
  height: auto;
}
70

Mark Otto's avatar
Mark Otto committed
71
72
// Mini reset for unique input types
input[type=image],
73
74
75
76
input[type=checkbox],
input[type=radio] {
  width: auto;
  height: auto;
77
  padding: 0;
78
  margin: 3px 0;
79
  *margin-top: 0; /* IE7 */
80
81
  line-height: normal;
  border: none;
82
  cursor: pointer;
83
84
}

85
// Reset the file input to browser defaults
86
input[type=file] {
87
88
  padding: initial;
  line-height: initial;
89
90
91
  border: initial;
  background-color: @white;
  background-color: initial;
92
93
94
  .box-shadow(none);
}

95
// Help out input buttons
96
97
98
99
100
101
102
input[type=button],
input[type=reset],
input[type=submit] {
  width: auto;
  height: auto;
}

103
// Set the height of select and file controls to match text inputs
104
105
select,
input[type=file] {
106
  height: @baseLineHeight * 1.5; /* In IE7, the height of the select element cannot be changed by height, only font-size */
107
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
108
  line-height: @baseLineHeight * 1.5;
Mark Otto's avatar
Mark Otto committed
109
}
110

111
// Chrome on Linux and Mobile Safari need background-color
112
select {
113
  width: 220px; // default input width + 10px of padding that doesn't get applied
114
  vertical-align: middle;
115
  background-color: @white;
116
117
}

Mark Otto's avatar
Mark Otto committed
118
// Make multiple select elements height not fixed
119
120
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
121
122
123
  height: inherit;
}

Mark Otto's avatar
Mark Otto committed
124
125
126
127
128
// Remove shadow from image inputs
input[type=image] {
  .box-shadow(none);
}

129
130
131
textarea {
  height: auto;
}
132

133

134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
  padding-left: 18px;
}
.radio input[type=radio],
.checkbox input[type=checkbox] {
  float: left;
  margin-left: -18px;
}

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

155
156
157
158
// Radios and checkboxes on same line
.radio.inline,
.checkbox.inline {
  display: inline-block;
159
  margin-bottom: 0;
160
161
162
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
163
  margin-left: 10px; // space out consecutive inline controls
164
165
}

166
167


168
169
170
// FOCUS STATE
// -----------

171
input,
172
textarea {
173
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
174
175
176
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
177
input:focus,
178
179
textarea:focus {
  border-color: rgba(82,168,236,.8);
180
  @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);
181
  .box-shadow(@shadow);
182
  outline: 0;
183
}
Mark Otto's avatar
Mark Otto committed
184
185
186
187
188
189
input[type=file]:focus,
input[type=checkbox]:focus,
select:focus {
  .box-shadow(none); // override for file inputs
  outline: 1px dotted #666; // Selet elements don't get box-shadow styles, so instead we do outline
}
190
191


192
193
194
195
196
197
198
199
200
201
202

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

204
// Grid style input sizes
205
206
207
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
208
.uneditable-input {
209
  float: none;
210
211
  margin-left: 0;
}
212
213
214
215
216

// This is a duplication of the main grid .columns() mixin, but subtracts 10px to account for input padding and border
.inputColumns(@columnSpan: 1) {
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) - 10;
}
217
218
input,
textarea,
219
.uneditable-input {
220
  // Default columns
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  &.span1     { .inputColumns(1); }
  &.span2     { .inputColumns(2); }
  &.span3     { .inputColumns(3); }
  &.span4     { .inputColumns(4); }
  &.span5     { .inputColumns(5); }
  &.span6     { .inputColumns(6); }
  &.span7     { .inputColumns(7); }
  &.span8     { .inputColumns(8); }
  &.span9     { .inputColumns(9); }
  &.span10    { .inputColumns(10); }
  &.span11    { .inputColumns(11); }
  &.span12    { .inputColumns(12); }
}

.selectColumns(@columnSpan: 1) {
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) + 10;
}
select {
  &.span1     { .selectColumns(1); }
  &.span2     { .selectColumns(2); }
  &.span3     { .selectColumns(3); }
  &.span4     { .selectColumns(4); }
  &.span5     { .selectColumns(5); }
  &.span6     { .selectColumns(6); }
  &.span7     { .selectColumns(7); }
  &.span8     { .selectColumns(8); }
  &.span9     { .selectColumns(9); }
  &.span10    { .selectColumns(10); }
  &.span11    { .selectColumns(11); }
  &.span12    { .selectColumns(12); }
251
252
}

253

254
255
256

// DISABLED STATE
// --------------
257

258
259
260
261
262
263
264
265
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
266
  border-color: #ddd;
267
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
268
269
}

270
271


272

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

276
277
278
// Mixin for form field states
.formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  // Set the text color
279
  > label,
280
281
282
  .help-block,
  .help-inline {
    color: @textColor;
283
  }
284
  // Style inputs accordingly
285
  input,
286
  select,
287
288
289
  textarea {
    color: @textColor;
    border-color: @borderColor;
290
    &:focus {
291
      border-color: darken(@borderColor, 10%);
Mark Otto's avatar
Mark Otto committed
292
      .box-shadow(0 0 6px lighten(@borderColor, 20%));
293
294
    }
  }
295
296
297
298
299
300
  // Give a small background color for input-prepend/-append
  .input-prepend .add-on,
  .input-append .add-on {
    color: @textColor;
    background-color: @backgroundColor;
    border-color: @textColor;
301
302
  }
}
303
// Warning
304
.control-group.warning {
305
  .formFieldState(@warningText, @warningText, @warningBackground);
306
307
308
}
// Error
.control-group.error {
309
  .formFieldState(@errorText, @errorText, @errorBackground);
310
311
}
// Success
312
.control-group.success {
313
  .formFieldState(@successText, @successText, @successBackground);
314
}
315

316
317
// HTML5 invalid states
// Shares styles with the .control-group.error above
318
319
320
input:focus:required:invalid,
textarea:focus:required:invalid,
select:focus:required:invalid {
321
322
323
324
325
326
327
328
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));    
  }
}

329
330
331
332
333
334


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

.form-actions {
335
336
337
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
338
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
339
340
341
  border-top: 1px solid #ddd;
}

342
343
344
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
345
  background-color: @white;
346
347
348
349
350
351
  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
352
.placeholder(@grayLight);
353
354
355



356
357
358
// HELP TEXT
// ---------

359
.help-block {
360
361
  margin-top: 5px;
  margin-bottom: 0;
362
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
363
}
364

Jacob Thornton's avatar
Jacob Thornton committed
365
.help-inline {
Jacob Thornton's avatar
Jacob Thornton committed
366
367
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
368
369
  display: inline;
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
370
}
371

372

373

374
375
// INPUT GROUPS
// ------------
376

Jacob Thornton's avatar
Jacob Thornton committed
377
// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
378
379
.input-prepend,
.input-append {
380
  margin-bottom: 5px;
381
  .clearfix(); // Clear the float to prevent wrapping
382
383
  input,
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
384
385
    .border-radius(0 3px 3px 0);
  }
386
387
388
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
389
390
391
392
393
  .add-on {
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
394
    height: @baseLineHeight;
395
    margin-right: -1px;
396
    padding: 4px 4px 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
397
    font-weight: normal;
398
    line-height: @baseLineHeight;
399
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
400
    text-align: center;
401
    text-shadow: 0 1px 0 @white;
402
403
    background-color: #f5f5f5;
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
404
405
406
    .border-radius(3px 0 0 3px);
  }
  .active {
407
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
408
409
410
    border-color: @green;
  }
}
411
.input-prepend {
Jacob Thornton's avatar
Jacob Thornton committed
412
413
414
415
  .add-on {
    *margin-top: 1px; /* IE6-7 */
  }
}
Mark Otto's avatar
Mark Otto committed
416
.input-append {
417
418
  input,
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
419
420
421
    float: left;
    .border-radius(3px 0 0 3px);
  }
422
423
424
  .uneditable-input {
    border-right-color: #ccc;    
  }
Jacob Thornton's avatar
Jacob Thornton committed
425
  .add-on {
426
427
    margin-right: 0;
    margin-left: -1px;
428
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
429
430
431
  }
}

432

433

434
435
436
// SEARCH FORM
// -----------

437
.search-query {
438
439
  padding-left: 14px;
  padding-right: 14px;
440
  margin-bottom: 0; // remove the default margin on all inputs
441
442
443
444
445
  .border-radius(14px);
}



446
447
448
449
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
450
451
// -----------------

452
453
454
.form-search,
.form-inline,
.form-horizontal {
455
456
457
458
459
460
461
462
  input,
  textarea,
  select,
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
}
463
464
.form-search label,
.form-inline label {
465
466
  display: inline-block;
}
467

468
469
// Margin to space out fieldsets
.control-group {
470
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
471
}
472

473
474
475
// Horizontal-specific styles
// --------------------------

476
.form-horizontal {
Mark Otto's avatar
Mark Otto committed
477
  // Increase spacing between groups
478
479
480
  .control-group {
    margin-bottom: @baseLineHeight;
  }
481
482
483
  // Float the labels left
  .control-group > label {
    float: left;
484
    width: 140px;
485
486
487
488
489
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
490
    margin-left: 160px;
491
492
493
  }
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
494
    padding-left: 160px;
495
  }
496
}