forms.less 9.97 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
110
  width: 220px; // default input width + 10px of padding that doesn't get applied
  padding: 0;
111
  vertical-align: middle;
112
  background-color: @white;
113
114
}

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

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

126
127
128
textarea {
  height: auto;
}
129

130

131

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

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

163
164


165
166
167
// FOCUS STATE
// -----------

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


189
190
191
192
193
194
195
196
197
198
199

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

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

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

250

251
252
253

// DISABLED STATE
// --------------
254

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

267
268


269

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

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

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

325
326
327
328
329
330


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

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

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



352
353
354
// HELP TEXT
// ---------

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

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

368

369

370
371
// INPUT GROUPS
// ------------
372

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

428

429

430
431
432
// SEARCH FORM
// -----------

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



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

// Common properties
446
447
// -----------------

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

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

469
470
471
// Horizontal-specific styles
// --------------------------

472
.form-horizontal {
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
}