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
287
288
  textarea {
    color: @textColor;
    border-color: @borderColor;
289
    &:focus {
290
      border-color: darken(@borderColor, 10%);
Mark Otto's avatar
Mark Otto committed
291
      .box-shadow(0 0 6px lighten(@borderColor, 20%));
292
293
    }
  }
294
295
296
297
298
299
  // 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;
300
301
  }
}
302
// Warning
303
.control-group.warning {
304
  .formFieldState(@warningText, @warningText, @warningBackground);
305
306
307
}
// Error
.control-group.error {
308
  .formFieldState(@errorText, @errorText, @errorBackground);
309
310
}
// Success
311
.control-group.success {
312
  .formFieldState(@successText, @successText, @successBackground);
313
}
314

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

328
329
330
331
332
333


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

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

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



355
356
357
// HELP TEXT
// ---------

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

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

371

372

373
374
// INPUT GROUPS
// ------------
375

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

431

432

433
434
435
// SEARCH FORM
// -----------

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



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

// Common properties
449
450
// -----------------

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

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

472
473
474
// Horizontal-specific styles
// --------------------------

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