forms.less 8.58 KB
Newer Older
1
/* Forms.less
2
 * Base styles for various input types, form layouts, and states
3
 * ------------------------------------------------------------- */
Jacob Thornton's avatar
Jacob Thornton committed
4

5

6
7
// FORM STYLES
// -----------
Jacob Thornton's avatar
Jacob Thornton committed
8
9
10

form {
  margin-bottom: @baseline;
11
}
12

13
14
15
16
17
18
// Groups of fields with labels on top (legends)
fieldset {
  margin-bottom: @baseline;
  padding-top: @baseline;
  legend {
    display: block;
Mark Otto's avatar
Mark Otto committed
19
    padding-left: 150px;
20
    font-size: @basefont * 1.5;
21
22
    line-height: 1;
    color: @grayDark;
Mark Otto's avatar
Mark Otto committed
23
24
    *padding: 0 0 5px 145px; /* IE6-7 */
    *line-height: 1.5; /* IE6-7 */
Jacob Thornton's avatar
Jacob Thornton committed
25
  }
26
}
27

28
// Parent element that clears floats and wraps labels and fields together
29
form .clearfix {
30
31
  margin-bottom: @baseline;
}
32

33
34
35
36
37
38
39
// Set font for forms
label,
input,
select,
textarea {
  #font > .sans-serif(normal,13px,normal);
}
40

41
42
43
// Float labels left
label {
  padding-top: 6px;
Mark Otto's avatar
Mark Otto committed
44
45
  font-size: @basefont;
  line-height: @baseline;
46
47
48
49
50
  float: left;
  width: 130px;
  text-align: right;
  color: @grayDark;
}
51

52
// Shift over the inside div to align all label's relevant content
53
form .input {
54
55
  margin-left: 150px;
}
56

57
58
59
60
61
// Checkboxs and radio buttons
input[type=checkbox],
input[type=radio] {
  cursor: pointer;
}
62

63
// Inputs, Textareas, Selects
64
input,
65
66
67
68
69
textarea,
select,
.uneditable-input {
  display: inline-block;
  width: 210px;
70
  height: @baseline;
71
  padding: 4px;
72
  font-size: @basefont;
73
74
75
76
77
  line-height: @baseline;
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
78
79
80
81
82
83

/* mini reset for non-html5 file types */
input[type=checkbox],
input[type=radio] {
  width: auto;
  height: auto;
84
  padding: 0;
85
  margin: 3px 0;
Mark Otto's avatar
Mark Otto committed
86
  *margin-top: 0; /* IE6-7 */
87
88
  line-height: normal;
  border: none;
89
90
91
}

input[type=file] {
92
93
94
95
  background-color: #fff;
  padding: initial;
  border: initial;
  line-height: initial;
96
97
98
99
100
101
102
103
104
105
  .box-shadow(none);
}

input[type=button],
input[type=reset],
input[type=submit] {
  width: auto;
  height: auto;
}

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

113
114
115
textarea {
  height: auto;
}
116

117
// For text that needs to appear as an input but should not be an input
118
.uneditable-input {
119
  background-color: #fff;
120
  display: block;
121
122
123
  border-color: #eee;
  .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  cursor: not-allowed;
124
}
125

126
127
128
129
130
131
132
133
134
// Placeholder text gets special styles; can't be bundled together though for some reason
:-moz-placeholder {
  color: @grayLight;
}
::-webkit-input-placeholder {
  color: @grayLight;
}

// Focus states
135
input,
136
textarea {
137
138
139
140
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
  .box-shadow(inset 0 1px 3px rgba(0,0,0,.1));
}
141
input:focus,
142
143
144
145
146
147
textarea:focus {
  outline: none;
  border-color: rgba(82,168,236,.8);
  @shadow: inset 0 1px 3px rgba(0,0,0,.1), 0 0 8px rgba(82,168,236,.6);
  .box-shadow(@shadow);
}
Mark Otto's avatar
Mark Otto committed
148
149
150
151
152
153
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
}
154

155
156
157
158
159
160
161
162
163
164
165
166
// Error styles
form div.error {
  background: lighten(@red, 57%);
  padding: 10px 0;
  margin: -10px 0 10px;
  .border-radius(4px);
  @error-text: desaturate(lighten(@red, 25%), 25%);
  > label,
  span.help-inline,
  span.help-block {
    color: @red;
  }
167
  input,
168
169
170
171
172
173
  textarea {
    border-color: @error-text;
    .box-shadow(0 0 3px rgba(171,41,32,.25));
    &:focus {
      border-color: darken(@error-text, 10%);
      .box-shadow(0 0 6px rgba(171,41,32,.5));
Jacob Thornton's avatar
Jacob Thornton committed
174
    }
175
176
177
178
179
  }
  .input-prepend,
  .input-append {
    span.add-on {
      background: lighten(@red, 50%);
Jacob Thornton's avatar
Jacob Thornton committed
180
      border-color: @error-text;
181
      color: darken(@error-text, 10%);
Jacob Thornton's avatar
Jacob Thornton committed
182
183
    }
  }
184
}
185

186
// Form element sizes
187
// TODO v2: remove duplication here and just stick to .input-[size] in light of adding .spanN sizes
188
189
190
191
.input-mini,
input.mini,
textarea.mini,
select.mini {
192
193
  width: 60px;
}
194
195
196
197
.input-small,
input.small,
textarea.small,
select.small {
198
199
  width: 90px;
}
200
201
202
203
.input-medium,
input.medium,
textarea.medium,
select.medium {
204
205
  width: 150px;
}
206
207
208
209
.input-large,
input.large,
textarea.large,
select.large {
210
211
  width: 210px;
}
212
213
214
215
.input-xlarge,
input.xlarge,
textarea.xlarge,
select.xlarge {
216
217
  width: 270px;
}
218
219
220
221
.input-xxlarge,
input.xxlarge,
textarea.xxlarge,
select.xxlarge {
222
223
224
  width: 530px;
}
textarea.xxlarge {
225
  overflow-y: auto;
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
251
252
253
254
255
// Grid style input sizes
// This is a duplication of the main grid .columns() mixin, but subtracts 10px to account for input padding and border
.formColumns(@columnSpan: 1) {
  width: ((@gridColumnWidth - 10) * @columnSpan) + ((@gridColumnWidth - 10) * (@columnSpan - 1));
  margin-left: 0;
}
input,
textarea,
select {
  // Default columns
  &.span1     { .formColumns(1); }
  &.span2     { .formColumns(2); }
  &.span3     { .formColumns(3); }
  &.span4     { .formColumns(4); }
  &.span5     { .formColumns(5); }
  &.span6     { .formColumns(6); }
  &.span7     { .formColumns(7); }
  &.span8     { .formColumns(8); }
  &.span9     { .formColumns(9); }
  &.span10    { .formColumns(10); }
  &.span11    { .formColumns(11); }
  &.span12    { .formColumns(12); }
  &.span13    { .formColumns(13); }
  &.span14    { .formColumns(14); }
  &.span15    { .formColumns(15); }
  &.span16    { .formColumns(16); }
}

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

// Actions (the buttons)
Mark Otto's avatar
Mark Otto committed
269
.actions {
Jacob Thornton's avatar
Jacob Thornton committed
270
271
272
273
274
275
  background: #f5f5f5;
  margin-top: @baseline;
  margin-bottom: @baseline;
  padding: (@baseline - 1) 20px @baseline 150px;
  border-top: 1px solid #ddd;
  .border-radius(0 0 3px 3px);
Mark Otto's avatar
Mark Otto committed
276
  .secondary-action {
Jacob Thornton's avatar
Jacob Thornton committed
277
278
279
280
281
282
283
284
285
286
287
288
289
    float: right;
    a {
      line-height: 30px;
      &:hover {
        text-decoration: underline;
      }
    }
  }
}

// Help Text
.help-inline,
.help-block {
290
  font-size: @basefont - 2;
Jacob Thornton's avatar
Jacob Thornton committed
291
  line-height: @baseline;
292
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
293
294
295
}
.help-inline {
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
296
297
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
Jacob Thornton's avatar
Jacob Thornton committed
298
}
299

Jacob Thornton's avatar
Jacob Thornton committed
300
301
302
303
304
305
306
// Big blocks of help text
.help-block {
  display: block;
  max-width: 600px;
}

// Inline Fields (input fields that appear as inline objects
Mark Otto's avatar
Mark Otto committed
307
.inline-inputs {
Jacob Thornton's avatar
Jacob Thornton committed
308
  color: @gray;
309
  span, input {
Jacob Thornton's avatar
Jacob Thornton committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    display: inline-block;
  }
  input.mini {
    width: 60px;
  }
  input.small {
    width: 90px;
  }
  span {
    padding: 0 2px 0 1px;
  }
}

// Allow us to put symbols and text within the input field for a cleaner look
Mark Otto's avatar
Mark Otto committed
324
325
.input-prepend,
.input-append {
326
  input {
Jacob Thornton's avatar
Jacob Thornton committed
327
328
329
330
331
332
333
334
    .border-radius(0 3px 3px 0);
  }
  .add-on {
    background: #f5f5f5;
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
335
    padding: 4px 4px 4px 5px;
336
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
337
338
339
340
341
    font-weight: normal;
    line-height: 18px;
    height: 18px;
    text-align: center;
    text-shadow: 0 1px 0 #fff;
342
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
343
344
345
346
347
348
349
350
    border-right-width: 0;
    .border-radius(3px 0 0 3px);
  }
  .active {
    background: lighten(@green, 30);
    border-color: @green;
  }
}
351
.input-prepend {
Jacob Thornton's avatar
Jacob Thornton committed
352
353
354
355
  .add-on {
    *margin-top: 1px; /* IE6-7 */
  }
}
Mark Otto's avatar
Mark Otto committed
356
.input-append {
357
  input {
Jacob Thornton's avatar
Jacob Thornton committed
358
359
360
361
362
363
364
365
366
367
368
    float: left;
    .border-radius(3px 0 0 3px);
  }
  .add-on {
    .border-radius(0 3px 3px 0);
    border-right-width: 1px;
    border-left-width: 0;
  }
}

// Stacked options for forms (radio buttons or checkboxes)
Mark Otto's avatar
Mark Otto committed
369
.inputs-list {
Jacob Thornton's avatar
Jacob Thornton committed
370
371
372
373
374
375
  margin: 0 0 5px;
  width: 100%;
  li {
    display: block;
    padding: 0;
    width: 100%;
376
377
378
379
380
381
382
383
384
385
386
  }
  label {
    display: block;
    float: none;
    width: auto;
    padding: 0;
    line-height: @baseline;
    text-align: left;
    white-space: normal;
    strong {
      color: @gray;
Jacob Thornton's avatar
Jacob Thornton committed
387
    }
388
389
390
    small {
      font-size: @basefont - 2;
      font-weight: normal;
Jacob Thornton's avatar
Jacob Thornton committed
391
392
    }
  }
393
394
395
396
397
398
399
400
401
402
403
  .inputs-list {
    margin-left: 25px;
    margin-bottom: 10px;
    padding-top: 0;
  }
  &:first-child {
    padding-top: 6px;
  }
  li + li {
    padding-top: 2px;
  }
Jacob Thornton's avatar
Jacob Thornton committed
404
405
406
407
408
409
410
  input[type=radio],
  input[type=checkbox] {
    margin-bottom: 0;
  }
}

// Stacked forms
411
.form-stacked {
412
  padding-left: 20px;
Jacob Thornton's avatar
Jacob Thornton committed
413
414
  fieldset {
    padding-top: @baseline / 2;
415
  }
Jacob Thornton's avatar
Jacob Thornton committed
416
  legend {
Mark Otto's avatar
Mark Otto committed
417
    padding-left: 0;
Jacob Thornton's avatar
Jacob Thornton committed
418
419
420
421
422
423
424
425
426
427
  }
  label {
    display: block;
    float: none;
    width: auto;
    font-weight: bold;
    text-align: left;
    line-height: 20px;
    padding-top: 0;
  }
Mark Otto's avatar
Mark Otto committed
428
  .clearfix {
Jacob Thornton's avatar
Jacob Thornton committed
429
430
431
432
433
    margin-bottom: @baseline / 2;
    div.input {
      margin-left: 0;
    }
  }
Mark Otto's avatar
Mark Otto committed
434
  .inputs-list {
Jacob Thornton's avatar
Jacob Thornton committed
435
436
437
438
439
440
441
442
443
    margin-bottom: 0;
    li {
      padding-top: 0;
      label {
        font-weight: normal;
        padding-top: 0;
      }
    }
  }
Mark Otto's avatar
Mark Otto committed
444
  div.error {
445
446
447
448
449
450
    padding-top: 10px;
    padding-bottom: 10px;
    padding-left: 10px;
    margin-top: 0;
    margin-left: -10px;
  }
Mark Otto's avatar
Mark Otto committed
451
  .actions {
452
453
454
    margin-left: -20px;
    padding-left: 20px;
  }
Jacob Thornton's avatar
Jacob Thornton committed
455
}