forms.less 9.99 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: 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

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

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

91
// Help out input buttons
92
93
94
95
96
97
98
input[type=button],
input[type=reset],
input[type=submit] {
  width: auto;
  height: auto;
}

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

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

Mark Otto's avatar
Mark Otto committed
114
// Make multiple select elements height not fixed
115
116
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
117
118
119
  height: inherit;
}

Mark Otto's avatar
Mark Otto committed
120
121
122
123
124
// Remove shadow from image inputs
input[type=image] {
  .box-shadow(none);
}

125
126
127
textarea {
  height: auto;
}
128

129

130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// 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
}

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

162
163


164
165
166
// FOCUS STATE
// -----------

167
input,
168
textarea {
169
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.1));
170
171
172
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
173
input:focus,
174
175
textarea:focus {
  border-color: rgba(82,168,236,.8);
176
  @shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 0 8px rgba(82,168,236,.6);
177
  .box-shadow(@shadow);
178
  outline: 0;
179
}
Mark Otto's avatar
Mark Otto committed
180
181
182
183
184
185
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
}
186
187


188
189
190
191
192
193
194
195
196
197
198

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

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

// 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;
}
213
214
input,
textarea,
215
.uneditable-input {
216
  // Default columns
217
218
219
220
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
  &.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); }
247
248
}

249

250
251
252

// DISABLED STATE
// --------------
253

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

266
267


268

269
270
// FORM FIELD FEEDBACK STATES
// --------------------------
271

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

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

324
325
326
327
328
329


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

.form-actions {
330
331
332
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
333
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
334
335
336
  border-top: 1px solid #ddd;
}

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



351
352
353
// HELP TEXT
// ---------

354
.help-block {
355
356
  margin-top: 5px;
  margin-bottom: 0;
357
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
358
}
359

Jacob Thornton's avatar
Jacob Thornton committed
360
.help-inline {
Jacob Thornton's avatar
Jacob Thornton committed
361
362
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
363
364
  display: inline;
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
365
}
366

367

368

369
370
// INPUT GROUPS
// ------------
371

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

427

428

429
430
431
// SEARCH FORM
// -----------

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



441
442
443
444
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
445
446
// -----------------

447
448
449
.form-search,
.form-inline,
.form-horizontal {
450
451
452
453
454
455
456
457
  input,
  textarea,
  select,
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
}
458
459
.form-search label,
.form-inline label {
460
461
  display: inline-block;
}
462

463
464
// Margin to space out fieldsets
.control-group {
465
  margin-bottom: @baseLineHeight / 2;
Jacob Thornton's avatar
Jacob Thornton committed
466
}
467

468
469
470
// Horizontal-specific styles
// --------------------------

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