forms.less 8.1 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
  width: ((@gridColumnWidth - 10) * @columnSpan) + ((@gridColumnWidth - 10) * (@columnSpan - 1));
  margin-left: 0;
}
input,
textarea,
154
155
select,
.uneditable-input {
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  // 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); }
}

175

176
177
178

// DISABLED STATE
// --------------
179

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

192
193


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

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



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

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

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// 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;
}



268
269
270
// HELP TEXT
// ---------

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

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

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

290

291

292
// INLINE FIELDS
293
// -------------
294

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

311

312

313
314
// INPUT GROUPS
// ------------
315

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

363

364

365
366
367
// SEARCH FORM
// -----------

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



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

// Common properties
378
379
// -----------------

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

389
390
391
// Horizontal-specific styles
// --------------------------

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