forms.less 8.22 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
45
46
textarea,
select,
.uneditable-input {
  display: inline-block;
  width: 210px;
47
  height: @baseLineHeight;
48
  padding: 4px;
49
50
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
51
52
53
54
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
55

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

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

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

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

96
97
98
99
100
// Chrome on Linux needs background color
select {
  background-color: @white;
}

Mark Otto's avatar
Mark Otto committed
101
102
103
104
105
// Make multiple select elements height not fixed
select[multiple] {
  height: inherit;
}

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

111
112
113
textarea {
  height: auto;
}
114

115

116

117
118
119
// FOCUS STATE
// -----------

120
input,
121
textarea {
122
  .box-shadow(inset 0 1px 3px rgba(0,0,0,.1));
123
124
125
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
}
126
input:focus,
127
128
129
130
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);
131
  outline: 0;
132
}
Mark Otto's avatar
Mark Otto committed
133
134
135
136
137
138
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
}
139
140


141
142
143
144
145
146
147
148
149
150
151

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

153
154
155
// 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) {
156
157
  display: inline-block;
  float: none;
158
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) - 10;
159
160
161
162
  margin-left: 0;
}
input,
textarea,
163
164
select,
.uneditable-input {
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  // 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); }
}

184

185
186
187

// DISABLED STATE
// --------------
188

189
190
191
192
193
194
195
196
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
197
  border-color: #ddd;
198
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
199
200
}

201
202


203
204
// FORM FIELD FEEDBACK STATES
// --------------------------
205

206
207
208
// Mixin for form field states
.formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  // Set the text color
209
  > label,
210
211
212
  .help-block,
  .help-inline {
    color: @textColor;
213
  }
214
  // Style inputs accordingly
215
  input,
216
217
218
  textarea {
    color: @textColor;
    border-color: @borderColor;
219
    &:focus {
220
221
      border-color: darken(@borderColor, 10%);
      .box-shadow(0 0 6px lighten(@borderColor, 20%);
222
223
    }
  }
224
225
226
227
228
229
  // 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;
230
231
  }
}
232
// Error
233
.control-group.error {
234
235
236
  .formFieldState(#b94a48, #ee5f5b, lighten(#ee5f5b, 30%));
}
// Warning
237
.control-group.warning {
238
239
240
  .formFieldState(#c09853, #ccae64, lighten(#CCAE64, 5%));
}
// Success
241
.control-group.success {
242
243
  .formFieldState(#468847, #57a957, lighten(#57a957, 30%));
}
244
245
246
247
248
249
250



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

.form-actions {
251
252
253
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
254
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
255
256
257
  border-top: 1px solid #ddd;
}

258
259
260
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
261
  background-color: @white;
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  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
:-moz-placeholder {
  color: @grayLight;
}
::-webkit-input-placeholder {
  color: @grayLight;
}



277
278
279
// HELP TEXT
// ---------

280
281
282
.help-text {
  margin-top: 5px;
  margin-bottom: 0;
283
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
284
}
285

Jacob Thornton's avatar
Jacob Thornton committed
286
.help-inline {
Jacob Thornton's avatar
Jacob Thornton committed
287
288
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
289
290
  display: inline;
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
291
}
292

Jacob Thornton's avatar
Jacob Thornton committed
293
294
295
296
297
298
// Big blocks of help text
.help-block {
  display: block;
  max-width: 600px;
}

299

300

301
// INLINE FIELDS
302
// -------------
303

Mark Otto's avatar
Mark Otto committed
304
.inline-inputs {
Jacob Thornton's avatar
Jacob Thornton committed
305
  color: @gray;
306
  span, input {
Jacob Thornton's avatar
Jacob Thornton committed
307
308
309
310
311
312
313
314
315
316
317
318
319
    display: inline-block;
  }
  input.mini {
    width: 60px;
  }
  input.small {
    width: 90px;
  }
  span {
    padding: 0 2px 0 1px;
  }
}

320

321

322
323
// INPUT GROUPS
// ------------
324

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

372

373

374
375
376
// SEARCH FORM
// -----------

377
.search-form .search-query {
378
379
380
381
382
  .border-radius(14px);
}



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

// Common properties
387
388
// -----------------

389
390
// Margin to space out fieldsets
.control-group {
391
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
392
}
393
394
395
396
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
397

398
399
400
// Horizontal-specific styles
// --------------------------

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
.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 the options list down to align with labels
  .control-list {
    padding-top: 6px; // has to be padding because margin collaspes
  }
  // Move over buttons in .form-actions to align with .controls
  .form-actions {
    padding-left: 150px;
  }
421
}