forms.less 9.94 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
  -webkit-margin-collapse: separate;
24
}
25

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

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

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

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

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

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

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

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

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

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

117
118
119
textarea {
  height: auto;
}
120

121

122

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

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

154
155


156
157
158
// FOCUS STATE
// -----------

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


180
181
182
183
184
185
186
187
188
189
190

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

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

// 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;
}
205
206
input,
textarea,
207
.uneditable-input {
208
  // Default columns
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
238
  &.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); }
239
240
}

241

242
243
244

// DISABLED STATE
// --------------
245

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

258
259


260

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

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

303
304
305
306
307
308
309
310
311
312
313
314
315
// 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%));    
  }
}

316
317
318
319
320
321


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

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

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



348
349
350
// HELP TEXT
// ---------

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

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

364

365

366
367
// INPUT GROUPS
// ------------
368

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

424

425

426
427
428
// SEARCH FORM
// -----------

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



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

// Common properties
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
457
458
.search-form label,
.inline-form label {
  display: inline-block;
}
459

460
461
// Margin to space out fieldsets
.control-group {
462
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
463
}
464
465
466
467
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
468

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

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
.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;
  }
488
}