forms.less 11.1 KB
Newer Older
1
2
3
//
// Forms
// --------------------------------------------------
4

5

6
// Non-controls
Mark Otto's avatar
Mark Otto committed
7
// -------------------------
Jacob Thornton's avatar
Jacob Thornton committed
8
9

form {
Mark Otto's avatar
Mark Otto committed
10
  margin: 0;
11
12
13
14
15
16
}

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
17
}
18

19
20
21
legend {
  display: block;
  width: 100%;
22
  padding: 0;
23
  margin-bottom: @line-height-base;
24
25
  font-size: (@font-size-base * 1.5);
  line-height: (@line-height-base * 2);
26
  color: @grayDark;
27
  border: 0;
28
  border-bottom: 1px solid #e5e5e5;
29
}
30

31
label {
32
  display: inline-block;
33
  margin-bottom: 5px;
34
  font-weight: bold;
35
}
36

37
38
39
// Form controls
// -------------------------

40
// Shared size and type resets
41
select,
42
43
44
45
46
47
48
49
50
51
52
53
54
55
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
56
input[type="color"] {
Mark Otto's avatar
Mark Otto committed
57
  display: inline-block;
58
  min-height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
59
  padding: 6px 9px;
60
  // margin-bottom: (@line-height-base / 2);
61
62
  font-size: @font-size-base;
  line-height: @line-height-base;
63
  color: @gray;
64
  vertical-align: middle;
65
66
67
  background-color: @input-background;
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
Mark Otto's avatar
Mark Otto committed
68
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
69
  .transition(~"border linear .2s, box-shadow linear .2s");
70
71
}

Mark Otto's avatar
Mark Otto committed
72
// Reset appearance properties for textual inputs and textarea
Mark Otto's avatar
Mark Otto committed
73
// Can't be on input[type=*] selectors or it's too specific
Mark Otto's avatar
Mark Otto committed
74
input,
Mark Otto's avatar
Mark Otto committed
75
select,
76
textarea {
Mark Otto's avatar
Mark Otto committed
77
  width: 100%;
Mark Otto's avatar
Mark Otto committed
78
}
Mark Otto's avatar
Mark Otto committed
79

80
81
82
83
84
85
86
87
88
89
90
// Reset width of input images, buttons, radios, checkboxes
input[type="file"],
input[type="image"],
input[type="submit"],
input[type="reset"],
input[type="button"],
input[type="radio"],
input[type="checkbox"] {
  width: auto; // Override of generic input selector
}

91
92
93
94
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
95

Mark Otto's avatar
Mark Otto committed
96
// Everything else
97
98
99
100
101
102
103
104
105
106
107
108
109
110
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
111
input[type="color"] {
112
113
114
115
116
  // Focus state
  &:focus {
    border-color: rgba(82,168,236,.8);
    outline: 0;
    outline: thin dotted \9; /* IE6-9 */
Mark Otto's avatar
Mark Otto committed
117
118
    //.box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
    .box-shadow(0 0 8px rgba(82,168,236,.6));
119
  }
120
}
121

Mark Otto's avatar
Mark Otto committed
122
// Position radios and checkboxes better
123
124
input[type="radio"],
input[type="checkbox"] {
125
  margin: 4px 0 0;
126
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
127
  line-height: normal;
128
}
Mark Otto's avatar
Mark Otto committed
129

130
// Set the height of select and file controls to match text inputs
131
select,
132
input[type="file"] {
133
134
  height: @input-height-base; /* In IE7, the height of the select element cannot be changed by height, only font-size. TODO: Check if this is still needed when dropping IE7 support */
  line-height: @input-height-base;
Mark Otto's avatar
Mark Otto committed
135
}
136

Mark Otto's avatar
Mark Otto committed
137
// Make multiple select elements height not fixed
138
139
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
140
  height: auto;
Mark Otto's avatar
Mark Otto committed
141
142
}

143
144
145
146
147
148
149
// Focus for select, file, radio, and checkbox
select:focus,
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
150

151

Mark Otto's avatar
Mark Otto committed
152
153
154
// Placeholder
// -------------------------

155
// Placeholder text gets special styles because when browsers invalidate entire lines if it doesn't understand a selector
Mark Otto's avatar
Mark Otto committed
156
157
158
159
160
input,
textarea {
  .placeholder();
}

161

162
163
164
165
166
167
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
168
  display: block;
169
  min-height: @line-height-base; // clear the floating input if there is no label text
170
  margin-bottom: (@line-height-base / 2);
171
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
172
173
174
175
176
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
  }
177
}
Mark Otto's avatar
Mark Otto committed
178

179
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
180
181
182
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
183
  float: left;
184
  margin-left: -20px;
185
}
Mark Otto's avatar
Mark Otto committed
186
187
.radio + .radio,
.checkbox + .checkbox {
188
  margin-top: ((@line-height-base / 4) * -1);
Mark Otto's avatar
Mark Otto committed
189
}
190
191
192
193

// Move the options list down to align with labels
.controls > .radio:first-child,
.controls > .checkbox:first-child {
194
  padding-top: 5px; // has to be padding because margin collaspes
195
196
}

197
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
198
199
.radio-inline,
.checkbox-inline {
200
  display: inline-block;
201
  padding-top: 5px;
Mark Otto's avatar
Mark Otto committed
202
  padding-left: 20px;
203
  margin-bottom: 0;
204
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
205
  font-weight: normal;
206
}
Mark Otto's avatar
Mark Otto committed
207
208
209
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
210
  margin-left: 10px; // space out consecutive inline controls
211
212
}

213
214


215
216
217
// INPUT SIZES
// -----------

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
select,
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
233
input[type="color"] {
234
  &.input-large {
235
    padding: @padding-large;
236
237
    font-size: @font-size-large;
    border-radius: @border-radius-large;
238
239
  }
  &.input-small {
240
    min-height: @input-height-small;
241
242
243
    padding: @padding-small;
    font-size: @font-size-small;
    border-radius: @border-radius-small;
244
245
  }
}
246

Mark Otto's avatar
Mark Otto committed
247
248
249
250
251


// GRID SIZING FOR INPUTS
// ----------------------

252
// Grid style input sizes
253
254
input[class*="span"],
select[class*="span"],
255
textarea[class*="span"] {
Mark Otto's avatar
Mark Otto committed
256
257
258
  float: none;
  margin-left: 0;
  margin-right: 0;
259
}
Mark Otto's avatar
Mark Otto committed
260

261
262
// Ensure input-prepend/append never wraps
.input-append input[class*="span"],
263
.input-prepend input[class*="span"] {
264
265
  display: inline-block;
}
266

267
268
input[class*="span"],
select[class*="span"],
269
textarea[class*="span"] {
270
  height: @input-height-base;
271
}
272

273

274
275
276

// DISABLED STATE
// --------------
277

278
// Disabled and read-only inputs
279
280
281
// Note: HTML5 says that inputs under a fieldset > legend:first-child won't be
//   disabled if the fieldset is disabled. Due to implementation difficulty,
//   we don't honor that edge case; we style them as disabled anyway.
282
283
284
285
286
287
288
289
290
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-background-disabled;
  }
Jacob Thornton's avatar
Jacob Thornton committed
291
}
292
// Explicitly reset the colors here
293
294
295
296
297
298
299
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
300
}
Jacob Thornton's avatar
Jacob Thornton committed
301

302
303


304

305
306
// FORM FIELD FEEDBACK STATES
// --------------------------
307

308
// Warning
309
.has-warning {
Mark Otto's avatar
Mark Otto committed
310
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-background);
311
312
}
// Error
313
.has-error {
Mark Otto's avatar
Mark Otto committed
314
  .formFieldState(@state-error-text, @state-error-text, @state-error-background);
315
316
}
// Success
317
.has-success {
Mark Otto's avatar
Mark Otto committed
318
  .formFieldState(@state-success-text, @state-success-text, @state-success-background);
319
}
320

321
322
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
323
324
325
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
326
327
328
329
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
330
331
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
332
333
334
  }
}

335
336
337
338
339
340


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

.form-actions {
341
342
343
  padding: (@line-height-base - 1) 20px @line-height-base;
  margin-top: @line-height-base;
  margin-bottom: @line-height-base;
344
  background-color: @form-actions-background;
345
  border-top: 1px solid #e5e5e5;
Mark Otto's avatar
Mark Otto committed
346
  .clear_float(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
347
348
}

349
350


351
352
353
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
354
355
.help-block,
.help-inline {
Mark Otto's avatar
Mark Otto committed
356
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
357
358
}

359
.help-block {
360
  display: block; // account for any element using help-block
361
  margin-bottom: (@line-height-base / 2);
Jacob Thornton's avatar
Jacob Thornton committed
362
}
363

Jacob Thornton's avatar
Jacob Thornton committed
364
.help-inline {
365
366
  display: inline-block;
  vertical-align: middle;
367
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
368
}
369

370

371

Mark Otto's avatar
Mark Otto committed
372
373
// Input groups
// --------------------------------------------------
374

Mark Otto's avatar
Mark Otto committed
375
376
377
378
// Base styles
// -------------------------
.input-group {
  display: table;
379

Mark Otto's avatar
Mark Otto committed
380
381
382
383
  // Undo padding and float of grid classes
  &[class*="span"] {
    float: none;
    padding: 0;
384
  }
385

386
  input,
387
  select {
Mark Otto's avatar
Mark Otto committed
388
    width: 100%;
389
390
  }
}
391

Mark Otto's avatar
Mark Otto committed
392
393
394
395
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
396
.input-group input {
Mark Otto's avatar
Mark Otto committed
397
398
399
  display: table-cell;
  margin: 0;
  border-radius: 0;
400
401
402
403
404
405
  &.input-small {
    border-radius: 0;
  }
  &.input-large {
    border-radius: 0;
  }
Jacob Thornton's avatar
Jacob Thornton committed
406
}
Mark Otto's avatar
Mark Otto committed
407
408
409
410
411
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
412
413
}

Mark Otto's avatar
Mark Otto committed
414
415
416
417
418
419
420
421
422
423
424
425
// Text input groups
// -------------------------
.input-group-addon {
  .box-sizing(border-box);
  padding: 6px 8px;
  font-size: @font-size-base;
  font-weight: normal;
  line-height: @line-height-base;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
  background-color: @grayLighter;
  border: 1px solid #ccc;
426
427
428
429
430
431

	&.input-small {
	  padding: @padding-small;
	  font-size: @font-size-small;
  }
	&.input-large {
432
		padding: @padding-large;
433
434
		font-size: @font-size-large;
	}
435
}
Mark Otto's avatar
Mark Otto committed
436
437
438
439
440

// Reset rounded corners
.input-group input:first-child,
.input-group-addon:first-child {
  .border-left-radius(@border-radius-base);
441
442
443
444
445
446
  &.input-small {
    .border-left-radius(@border-radius-small);
  }
  &.input-large {
    .border-left-radius(@border-radius-large);
  }
447
}
Mark Otto's avatar
Mark Otto committed
448
449
.input-group-addon:first-child {
  border-right: 0;
450
}
Mark Otto's avatar
Mark Otto committed
451
452
453
.input-group input:last-child,
.input-group-addon:last-child {
  .border-right-radius(@border-radius-base);
454
455
456
457
458
459
  &.input-small {
    .border-right-radius(@border-radius-small);
  }
  &.input-large {
    .border-right-radius(@border-radius-large);
  }
460
}
Mark Otto's avatar
Mark Otto committed
461
462
.input-group-addon:last-child {
  border-left: 0;
463
464
}

Mark Otto's avatar
Mark Otto committed
465
466
// Button input groups
// -------------------------
467
468
.input-group-btn {
  position: relative;
Mark Otto's avatar
Mark Otto committed
469
  white-space: nowrap;
470
}
Mark Otto's avatar
Mark Otto committed
471
.input-group-btn > .btn {
472
  position: relative;
Mark Otto's avatar
Mark Otto committed
473
474
475
  float: left; // Collapse white-space
  border-radius: 0;
  + .btn {
476
    margin-left: -1px;
477
  }
478
479
480
481
  // Bring the "active" button to the front
  &:hover,
  &:active {
    z-index: 2;
482
  }
Mark Otto's avatar
Mark Otto committed
483
}
484
485
486
487
488
489
490
491
492

// Prepended buttons
.input-group-btn:first-child {
  // Round the left corners only
  > .btn:first-child,
  > .dropdown-toggle:first-child {
    .border-left-radius(@border-radius-base);
    &.btn-large { .border-left-radius(@border-radius-large); }
    &.btn-small { .border-left-radius(@border-radius-small); }
493
  }
494
495
496
497
498
499
500
501
502
503
}

// Appended buttons
.input-group-btn:last-child {
  // Round the right corners only
  > .btn:last-child,
  > .dropdown-toggle {
    .border-right-radius(@border-radius-base);
    &.btn-large { .border-right-radius(@border-radius-large); }
    &.btn-small { .border-right-radius(@border-radius-small); }
504
  }
505
}
Mark Otto's avatar
Mark Otto committed
506
507
508
509
510
511



// Horizontal forms
// --------------------------------------------------

Mark Otto's avatar
Mark Otto committed
512
513
514
@media screen and (min-width: 768px) {

  .form-horizontal {
515

Mark Otto's avatar
Mark Otto committed
516
517
518
519
520
521
522
523
    // Increase spacing between groups
    .control-group {
      position: relative;
      margin-bottom: @line-height-base;
      .clear_float();

      input,
      select,
524
      textarea {
Mark Otto's avatar
Mark Otto committed
525
526
        margin-bottom: 0;
      }
527
    }
Mark Otto's avatar
Mark Otto committed
528

Mark Otto's avatar
Mark Otto committed
529
530
531
    // Float the labels left
    .control-group > .control-label {
      float: left;
532
      width: (@component-offset-horizontal - 20);
Mark Otto's avatar
Mark Otto committed
533
534
535
      padding-top: 6px;
      text-align: right;
    }
Mark Otto's avatar
Mark Otto committed
536

Mark Otto's avatar
Mark Otto committed
537
538
539
540
    // Move over all input controls and content over
    .control-group > .controls {
      margin-left: @component-offset-horizontal;
    }
Mark Otto's avatar
Mark Otto committed
541

Mark Otto's avatar
Mark Otto committed
542
  }
Mark Otto's avatar
Mark Otto committed
543
}