forms.less 9.84 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
  margin-bottom: @baseLineHeight;
12
}
13

14
// Groups of fields with labels on top (legends)
15
16
17
legend {
  display: block;
  width: 100%;
18
19
20
  margin-bottom: @baseLineHeight * 1.5;
  font-size: @baseFontSize * 1.5;
  line-height: @baseLineHeight * 2;
21
22
  color: @grayDark;
  border-bottom: 1px solid #eee;
23
}
24

25
26
27
28
29
// Set font for forms
label,
input,
select,
textarea {
30
  #font > .sans-serif(normal,@baseFontSize,@baseLineHeight);
31
}
32

33
// Identify controls by their labels
34
label {
35
36
  display: block;
  margin-bottom: 5px;
37
38
  color: @grayDark;
}
39

40
// Inputs, Textareas, Selects
41
input,
42
43
44
textarea,
select,
.uneditable-input {
45
  display: block;
46
  width: 210px;
47
  height: @baseLineHeight;
48
  padding: 4px;
49
  margin-bottom: 9px;
50
51
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
52
53
54
55
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
56

Mark Otto's avatar
Mark Otto committed
57
58
// Mini reset for unique input types
input[type=image],
59
60
61
62
input[type=checkbox],
input[type=radio] {
  width: auto;
  height: auto;
63
  padding: 0;
64
  margin: 3px 0;
Mark Otto's avatar
Mark Otto committed
65
  *margin-top: 0; /* IE6-7 */
66
67
  line-height: normal;
  border: none;
68
  cursor: pointer;
69
70
}

71
// Reset the file input to browser defaults
72
input[type=file] {
73
74
  padding: initial;
  line-height: initial;
75
76
77
  border: initial;
  background-color: @white;
  background-color: initial;
78
79
80
  .box-shadow(none);
}

81
// Help out input buttons
82
83
84
85
86
87
88
input[type=button],
input[type=reset],
input[type=submit] {
  width: auto;
  height: auto;
}

89
// Set the height of select and file controls to match text inputs
90
91
select,
input[type=file] {
92
  height: @baseLineHeight * 1.5; // In IE7, the height of the select element cannot be changed by height, only font-size
93
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
94
  line-height: @baseLineHeight * 1.5;
Mark Otto's avatar
Mark Otto committed
95
}
96

97
// Chrome on Linux and Mobile Safari need background-color
98
select {
99
100
  width: 220px; // default input width + 10px of padding that doesn't get applied
  padding: 0;
101
  vertical-align: middle;
102
  background-color: @white;
103
104
}

Mark Otto's avatar
Mark Otto committed
105
// Make multiple select elements height not fixed
106
107
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
108
109
110
  height: inherit;
}

Mark Otto's avatar
Mark Otto committed
111
112
113
114
115
// Remove shadow from image inputs
input[type=image] {
  .box-shadow(none);
}

116
117
118
textarea {
  height: auto;
}
119

120

121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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
}

142
143
144
145
// Radios and checkboxes on same line
.radio.inline,
.checkbox.inline {
  display: inline-block;
146
  margin-bottom: 0;
147
148
149
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
150
  margin-left: 10px; // space out consecutive inline controls
151
152
}

153
154


155
156
157
// FOCUS STATE
// -----------

158
input,
159
textarea {
160
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.1));
161
162
163
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
164
input:focus,
165
166
textarea:focus {
  border-color: rgba(82,168,236,.8);
167
  @shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 0 8px rgba(82,168,236,.6);
168
  .box-shadow(@shadow);
169
  outline: 0;
170
}
Mark Otto's avatar
Mark Otto committed
171
172
173
174
175
176
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
}
177
178


179
180
181
182
183
184
185
186
187
188
189

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

191
// Grid style input sizes
192
193
194
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
195
.uneditable-input {
196
  float: none;
197
198
  margin-left: 0;
}
199
200
201
202
203

// 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;
}
204
205
input,
textarea,
206
.uneditable-input {
207
  // Default columns
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  &.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); }
238
239
}

240

241
242
243

// DISABLED STATE
// --------------
244

245
246
247
248
249
250
251
252
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
253
  border-color: #ddd;
254
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
255
256
}

257
258


259

260
261
// FORM FIELD FEEDBACK STATES
// --------------------------
262

263
264
265
// Mixin for form field states
.formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  // Set the text color
266
  > label,
267
268
269
  .help-block,
  .help-inline {
    color: @textColor;
270
  }
271
  // Style inputs accordingly
272
  input,
273
274
275
  textarea {
    color: @textColor;
    border-color: @borderColor;
276
    &:focus {
277
      border-color: darken(@borderColor, 10%);
Mark Otto's avatar
Mark Otto committed
278
      .box-shadow(0 0 6px lighten(@borderColor, 20%));
279
280
    }
  }
281
282
283
284
285
286
  // 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;
287
288
  }
}
289
// Error
290
.control-group.error {
291
292
293
  .formFieldState(#b94a48, #ee5f5b, lighten(#ee5f5b, 30%));
}
// Warning
294
.control-group.warning {
295
296
297
  .formFieldState(#c09853, #ccae64, lighten(#CCAE64, 5%));
}
// Success
298
.control-group.success {
299
300
  .formFieldState(#468847, #57a957, lighten(#57a957, 30%));
}
301

302
303
304
305
306
307
308
309
310
311
312
313
314
// HTML5 invalid states
// Shares styles with the .control-group.error above
input:invalid,
textarea:invalid,
select:invalid {
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
    .box-shadow(0 0 6px lighten(#ee5f5b, 20%));    
  }
}

315
316
317
318
319
320


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

.form-actions {
321
322
323
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
324
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
325
326
327
  border-top: 1px solid #ddd;
}

328
329
330
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
331
  background-color: @white;
332
333
334
335
336
337
  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
338
input:-moz-placeholder {
339
340
  color: @grayLight;
}
341
input::-webkit-input-placeholder {
342
343
344
345
346
  color: @grayLight;
}



347
348
349
// HELP TEXT
// ---------

350
.help-block {
351
352
  margin-top: 5px;
  margin-bottom: 0;
353
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
354
}
355

Jacob Thornton's avatar
Jacob Thornton committed
356
.help-inline {
Jacob Thornton's avatar
Jacob Thornton committed
357
358
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
359
360
  display: inline;
  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
  .clearfix(); // Clear the float to prevent wrapping
373
374
  input,
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
375
376
    .border-radius(0 3px 3px 0);
  }
377
378
379
  .uneditable-input {
    border-left-color: #ccc;
  }
Jacob Thornton's avatar
Jacob Thornton committed
380
381
382
383
384
  .add-on {
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
385
    height: @baseLineHeight;
386
    margin-right: -1px;
387
    padding: 4px 4px 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
388
    font-weight: normal;
389
    line-height: @baseLineHeight;
390
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
391
    text-align: center;
392
    text-shadow: 0 1px 0 @white;
393
394
    background-color: #f5f5f5;
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
395
396
397
    .border-radius(3px 0 0 3px);
  }
  .active {
398
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
399
400
401
    border-color: @green;
  }
}
402
.input-prepend {
Jacob Thornton's avatar
Jacob Thornton committed
403
404
405
406
  .add-on {
    *margin-top: 1px; /* IE6-7 */
  }
}
Mark Otto's avatar
Mark Otto committed
407
.input-append {
408
409
  input,
  .uneditable-input {
Jacob Thornton's avatar
Jacob Thornton committed
410
411
412
    float: left;
    .border-radius(3px 0 0 3px);
  }
413
414
415
  .uneditable-input {
    border-right-color: #ccc;    
  }
Jacob Thornton's avatar
Jacob Thornton committed
416
  .add-on {
417
418
    margin-right: 0;
    margin-left: -1px;
419
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
420
421
422
  }
}

423

424

425
426
427
// SEARCH FORM
// -----------

428
.search-query {
429
430
  padding-left: 14px;
  padding-right: 14px;
431
  margin-bottom: 0; // remove the default margin on all inputs
432
433
434
435
436
  .border-radius(14px);
}



437
438
439
440
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
441
442
// -----------------

443
444
445
446
447
448
449
450
451
452
453
454
.search-form,
.inline-form,
.horizontal-form {
  input,
  textarea,
  select,
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
}

455
456
// Margin to space out fieldsets
.control-group {
457
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
458
}
459
460
461
462
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
463

464
465
466
// Horizontal-specific styles
// --------------------------

467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
.horizontal-form {
  // Float the labels left
  .control-group > label {
    float: left;
    width: 130px;
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
    margin-left: 150px;
  }
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
    padding-left: 150px;
  }
483
}