forms.less 8.06 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
// Chrome on Linux and Mobile Safari need background-color
97
98
select {
  background-color: @white;
99
  vertical-align: middle;
100
101
}

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

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

113
114
115
textarea {
  height: auto;
}
116

117

118

119
120
121
// FOCUS STATE
// -----------

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


143
144
145
146
147
148
149
150
151
152
153

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

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

186

187
188
189

// DISABLED STATE
// --------------
190

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

203
204


205
206
// FORM FIELD FEEDBACK STATES
// --------------------------
207

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



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

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

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



279
280
281
// HELP TEXT
// ---------

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

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

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

301

302

303
304
// INPUT GROUPS
// ------------
305

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

352

353

354
355
356
// SEARCH FORM
// -----------

357
.search-form .search-query {
358
359
360
361
362
  .border-radius(14px);
}



363
364
365
366
// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
367
368
// -----------------

369
370
// Margin to space out fieldsets
.control-group {
371
  margin-bottom: @baseLineHeight;
Jacob Thornton's avatar
Jacob Thornton committed
372
}
373
374
375
376
// Bold the labels so they stand out
.control-group > label {
  font-weight: bold;
}
377

378
379
380
// Horizontal-specific styles
// --------------------------

381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
.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;
  }
401
}