forms.less 7.9 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
// 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
41
42
43
44
// Checkboxs and radio buttons
input[type=checkbox],
input[type=radio] {
  cursor: pointer;
}
45

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

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

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

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

91
92
select,
input[type=file] {
93
94
  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;
95
  *margin-top: 4px; /* For IE7, add top margin to align select with labels */
Mark Otto's avatar
Mark Otto committed
96
}
97

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

104
105
106
textarea {
  height: auto;
}
107

108

109

110
111
112
// FOCUS STATE
// -----------

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


134
135
136
137
138
139
140
141
142
143
144

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

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

176

177
178
179

// DISABLED STATE
// --------------
180

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

193
194
195
196
197
198
199
200
201
202
203


// ERROR STATE
// -----------

// Set color of error text
@error-text: desaturate(lighten(@red, 25%), 25%);

// Style the background of control-groups with errors
.has-error {
  background: lighten(@red, 55%);
204
  padding: (@baseLineHeight / 2) 0;
205
206
207
208
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
  margin: -10px 0 10px;
  .border-radius(4px);
  > label,
  span.help-inline,
  span.help-block {
    color: @red;
  }
  input,
  textarea,
  select {
    border-color: @error-text;
    .box-shadow(0 0 3px rgba(171,41,32,.25));
    &:focus {
      border-color: darken(@error-text, 10%);
      .box-shadow(0 0 6px rgba(171,41,32,.5));
    }
  }
  .input-prepend,
  .input-append {
    span.add-on {
      background: lighten(@red, 50%);
      border-color: @error-text;
      color: darken(@error-text, 10%);
    }
  }
}



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

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

245

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



265
266
267
// HELP TEXT
// ---------

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

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

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

287
288

// INLINE FIELDS
289
// -------------
290

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

307

308
309
// INPUT GROUPS
// ------------
310

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

358

359
360


361
362
363
364
365
366
367
368
369
// SEARCH FORM
// -----------

.form-search .search-query {
  .border-radius(14px);
}



370
371
372
373
374
// HORIZONTAL & VERTICAL FORMS
// ---------------------------


// Common properties
375
376
// -----------------

377
378
// Margin to space out fieldsets
.control-group {
379
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
380
381
}

382
383
384
385
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
386

387
388
389
// Lists of controls (checkboxes and radios)
.control-list {
}
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

// Horizontal-specific styles
// --------------------------

// Float the labels left
.form-horizontal .control-group > label {
  float: left;
  width: 130px;
  padding-top: 5px;
  text-align: right;
}
// Move over all input controls and content
.form-horizontal .controls {
  margin-left: 150px;
}
// Move the options list down to align with labels
.form-horizontal .control-list {
  padding-top: 6px; // has to be padding because margin collaspes
}
// Move over buttons in .form-actions to align with .controls
.form-horizontal .form-actions {
  padding-left: 150px;
}