forms.less 8.55 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
}
24

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

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

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

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

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

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

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

97
// Chrome on Linux and Mobile Safari need background-color
98
99
select {
  background-color: @white;
100
  vertical-align: middle;
101
102
}

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

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

114
115
116
textarea {
  height: auto;
}
117

118

119

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



142
143
144
// FOCUS STATE
// -----------

145
input,
146
textarea {
147
  .box-shadow(inset 0 1px 3px rgba(0,0,0,.1));
148
149
150
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
151
input:focus,
152
153
154
155
textarea:focus {
  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);
156
  outline: 0;
157
}
Mark Otto's avatar
Mark Otto committed
158
159
160
161
162
163
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
}
164
165


166
167
168
169
170
171
172
173
174
175
176

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

178
179
180
// 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) {
181
  float: none;
182
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) - 10;
183
184
185
186
  margin-left: 0;
}
input,
textarea,
187
188
select,
.uneditable-input {
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  // 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); }
}

208

209
210
211

// DISABLED STATE
// --------------
212

213
214
215
216
217
218
219
220
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
221
  border-color: #ddd;
222
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
223
224
}

225
226


227

228
229
// FORM FIELD FEEDBACK STATES
// --------------------------
230

231
232
233
// Mixin for form field states
.formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  // Set the text color
234
  > label,
235
236
237
  .help-block,
  .help-inline {
    color: @textColor;
238
  }
239
  // Style inputs accordingly
240
  input,
241
242
243
  textarea {
    color: @textColor;
    border-color: @borderColor;
244
    &:focus {
245
      border-color: darken(@borderColor, 10%);
Mark Otto's avatar
Mark Otto committed
246
      .box-shadow(0 0 6px lighten(@borderColor, 20%));
247
248
    }
  }
249
250
251
252
253
254
  // 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;
255
256
  }
}
257
// Error
258
.control-group.error {
259
260
261
  .formFieldState(#b94a48, #ee5f5b, lighten(#ee5f5b, 30%));
}
// Warning
262
.control-group.warning {
263
264
265
  .formFieldState(#c09853, #ccae64, lighten(#CCAE64, 5%));
}
// Success
266
.control-group.success {
267
268
  .formFieldState(#468847, #57a957, lighten(#57a957, 30%));
}
269
270
271
272
273
274
275



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

.form-actions {
276
277
278
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
279
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
280
281
282
  border-top: 1px solid #ddd;
}

283
284
285
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
286
  background-color: @white;
287
288
289
290
291
292
  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
293
input:-moz-placeholder {
294
295
  color: @grayLight;
}
296
input::-webkit-input-placeholder {
297
298
299
300
301
  color: @grayLight;
}



302
303
304
// HELP TEXT
// ---------

305
.help-block {
306
307
  margin-top: 5px;
  margin-bottom: 0;
308
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
309
}
310

Jacob Thornton's avatar
Jacob Thornton committed
311
.help-inline {
Jacob Thornton's avatar
Jacob Thornton committed
312
313
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
314
315
  display: inline;
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
316
}
317

318

319

320
321
// INPUT GROUPS
// ------------
322

Jacob Thornton's avatar
Jacob Thornton committed
323
// 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
  margin-bottom: 5px;
327
  .clearfix(); // Clear the float to prevent wrapping
328
  input {
Jacob Thornton's avatar
Jacob Thornton committed
329
330
331
332
333
334
335
    .border-radius(0 3px 3px 0);
  }
  .add-on {
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
336
    height: @baseLineHeight;
337
    margin-right: -1px;
338
    padding: 4px 4px 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
339
    font-weight: normal;
340
    line-height: @baseLineHeight;
341
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
342
    text-align: center;
343
    text-shadow: 0 1px 0 @white;
344
345
    background-color: #f5f5f5;
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
346
347
348
    .border-radius(3px 0 0 3px);
  }
  .active {
349
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
350
351
352
    border-color: @green;
  }
}
353
.input-prepend {
Jacob Thornton's avatar
Jacob Thornton committed
354
355
356
357
  .add-on {
    *margin-top: 1px; /* IE6-7 */
  }
}
Mark Otto's avatar
Mark Otto committed
358
.input-append {
359
  input {
Jacob Thornton's avatar
Jacob Thornton committed
360
361
362
363
    float: left;
    .border-radius(3px 0 0 3px);
  }
  .add-on {
364
365
    margin-right: 0;
    margin-left: -1px;
366
    .border-radius(0 3px 3px 0);
Jacob Thornton's avatar
Jacob Thornton committed
367
368
369
  }
}

370

371

372
373
374
// SEARCH FORM
// -----------

375
.search-query {
376
377
  padding-left: 14px;
  padding-right: 14px;
378
  margin-bottom: 0; // remove the default margin on all inputs
379
380
381
382
383
  .border-radius(14px);
}



384
385
386
387
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
388
389
// -----------------

390
391
392
393
394
395
396
397
398
399
400
401
.search-form,
.inline-form,
.horizontal-form {
  input,
  textarea,
  select,
  .uneditable-input {
    display: inline-block;
    margin-bottom: 0;
  }
}

402
403
// Margin to space out fieldsets
.control-group {
404
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
405
}
406
407
408
409
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
410

411
412
413
// Horizontal-specific styles
// --------------------------

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
.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;
  }
430
}