forms.less 8.08 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
8
// GENERAL STYLES
// --------------
Jacob Thornton's avatar
Jacob Thornton committed
9

10
// Make all forms have space below them
Jacob Thornton's avatar
Jacob Thornton committed
11
form {
12
  margin-bottom: @baseLineHeight;
13
}
14

15
// Groups of fields with labels on top (legends)
16
17
18
legend {
  display: block;
  width: 100%;
19
20
21
  margin-bottom: @baseLineHeight * 1.5;
  font-size: @baseFontSize * 1.5;
  line-height: @baseLineHeight * 2;
22
23
  color: @grayDark;
  border-bottom: 1px solid #eee;
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
46
47
textarea,
select,
.uneditable-input {
  display: inline-block;
  width: 210px;
48
  height: @baseLineHeight;
49
  padding: 4px;
50
51
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
52
53
54
55
  color: @gray;
  border: 1px solid #ccc;
  .border-radius(3px);
}
56

57
/* Mini reset for unique input types */
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
  background-color: @white;
73
  background-color: initial;
74
75
76
  padding: initial;
  border: initial;
  line-height: 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
92
  height: @baseLineHeight * 1.5; // In IE7, the height of the select element cannot be changed by height, only font-size
  line-height: @baseLineHeight * 1.5;
93
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
94
}
95

Mark Otto's avatar
Mark Otto committed
96
97
// Make multiple select elements height not fixed
select[multiple] {
98
  background-color: @white; // Fixes Chromium bug?
Mark Otto's avatar
Mark Otto committed
99
100
101
  height: inherit;
}

102
103
104
textarea {
  height: auto;
}
105

106

107

108
109
110
// FOCUS STATE
// -----------

111
input,
112
textarea {
113
114
115
116
  @transition: border linear .2s, box-shadow linear .2s;
  .transition(@transition);
  .box-shadow(inset 0 1px 3px rgba(0,0,0,.1));
}
117
input:focus,
118
textarea:focus {
Jacob Thornton's avatar
Jacob Thornton committed
119
  outline: 0;
120
121
122
123
  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
124
125
126
127
128
129
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
}
130
131


132
133
134
135
136
137
138
139
140
141
142

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

144
145
146
// 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) {
147
148
  display: inline-block;
  float: none;
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  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); }
}

174

175
176
177

// DISABLED STATE
// --------------
178

179
180
181
182
183
184
185
186
// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  background-color: #f5f5f5;
187
  border-color: #ddd;
188
  cursor: not-allowed;
Jacob Thornton's avatar
Jacob Thornton committed
189
190
}

191
192


193
194
// FORM FIELD FEEDBACK STATES
// --------------------------
195

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



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

.form-actions {
241
242
243
  padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  margin-top: @baseLineHeight;
  margin-bottom: @baseLineHeight;
244
  background-color: #f5f5f5;
Jacob Thornton's avatar
Jacob Thornton committed
245
246
247
  border-top: 1px solid #ddd;
}

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  background-color: @white;
  display: block;
  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;
}



267
268
269
// HELP TEXT
// ---------

270
271
272
.help-text {
  margin-top: 5px;
  margin-bottom: 0;
273
  color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
274
}
275

Jacob Thornton's avatar
Jacob Thornton committed
276
.help-inline {
277
  display: inline;
Jacob Thornton's avatar
Jacob Thornton committed
278
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
279
280
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
Jacob Thornton's avatar
Jacob Thornton committed
281
}
282

Jacob Thornton's avatar
Jacob Thornton committed
283
284
285
286
287
288
// Big blocks of help text
.help-block {
  display: block;
  max-width: 600px;
}

289

290

291
// INLINE FIELDS
292
// -------------
293

Mark Otto's avatar
Mark Otto committed
294
.inline-inputs {
Jacob Thornton's avatar
Jacob Thornton committed
295
  color: @gray;
296
  span, input {
Jacob Thornton's avatar
Jacob Thornton committed
297
298
299
300
301
302
303
304
305
306
307
308
309
    display: inline-block;
  }
  input.mini {
    width: 60px;
  }
  input.small {
    width: 90px;
  }
  span {
    padding: 0 2px 0 1px;
  }
}

310

311

312
313
// INPUT GROUPS
// ------------
314

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

362

363

364
365
366
// SEARCH FORM
// -----------

367
.search-form .search-query {
368
369
370
371
372
  .border-radius(14px);
}



373
374
375
376
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
377
378
// -----------------

379
380
// Margin to space out fieldsets
.control-group {
381
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
382
}
383
384
385
386
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
387

388
389
390
// Horizontal-specific styles
// --------------------------

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
.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;
  }
411
}