forms.less 8.11 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

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

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

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

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

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

101
102
103
textarea {
  height: auto;
}
104

105

106

107
108
109
// FOCUS STATE
// -----------

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


131
132
133
134
135
136
137
138
139
140
141

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

143
144
145
// 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) {
146
147
  display: inline-block;
  float: none;
148
149
150
151
152
  width: ((@gridColumnWidth - 10) * @columnSpan) + ((@gridColumnWidth - 10) * (@columnSpan - 1));
  margin-left: 0;
}
input,
textarea,
153
154
select,
.uneditable-input {
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  // 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
// For text that needs to appear as an input but should not be an input
.uneditable-input {
  display: block;
251
  background-color: @white;
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  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 {
Jacob Thornton's avatar
Jacob Thornton committed
277
278
  *position: relative; /* IE6-7 */
  *top: -5px; /* IE6-7 */
279
280
  display: inline;
  padding-left: 5px;
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
323
    position: relative;
    z-index: 2;
Jacob Thornton's avatar
Jacob Thornton committed
324
325
326
327
    float: left;
    display: block;
    width: auto;
    min-width: 16px;
328
    height: @baseLineHeight;
329
    margin-right: -1px;
330
    padding: 4px 4px 4px 5px;
Jacob Thornton's avatar
Jacob Thornton committed
331
    font-weight: normal;
332
    line-height: @baseLineHeight;
333
    color: @grayLight;
Jacob Thornton's avatar
Jacob Thornton committed
334
    text-align: center;
335
    text-shadow: 0 1px 0 @white;
336
337
    background-color: #f5f5f5;
    border: 1px solid #ccc;
Jacob Thornton's avatar
Jacob Thornton committed
338
339
340
    .border-radius(3px 0 0 3px);
  }
  .active {
341
    background-color: lighten(@green, 30);
Jacob Thornton's avatar
Jacob Thornton committed
342
343
344
    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
    float: left;
    .border-radius(3px 0 0 3px);
  }
  .add-on {
356
357
    margin-right: 0;
    margin-left: -1px;
358
    .border-radius(0 3px 3px 0);
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
}