forms.less 11.3 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: @gray-dark;
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
  background-color: @input-bg;
66
67
  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
95
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

96
97
98
99
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
100

Mark Otto's avatar
Mark Otto committed
101
// Everything else
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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"],
116
input[type="color"] {
117
118
119
120
121
  // 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
122
123
    //.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));
124
  }
125
}
126

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

135
// Set the height of select and file controls to match text inputs
136
select,
137
input[type="file"] {
138
139
  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
140
}
141

Mark Otto's avatar
Mark Otto committed
142
// Make multiple select elements height not fixed
143
144
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
145
  height: auto;
Mark Otto's avatar
Mark Otto committed
146
147
}

148
149
150
151
152
153
154
// Focus for select, file, radio, and checkbox
select:focus,
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
155

156

Mark Otto's avatar
Mark Otto committed
157
158
159
// Placeholder
// -------------------------

160
// 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
161
162
163
164
165
input,
textarea {
  .placeholder();
}

166

167
168
169
170
171
172
// CHECKBOXES & RADIOS
// -------------------

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

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

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

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

218
219


220
221
222
// INPUT SIZES
// -----------

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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"],
238
input[type="color"] {
239
  &.input-large {
240
    padding: @padding-large;
241
242
    font-size: @font-size-large;
    border-radius: @border-radius-large;
243
244
  }
  &.input-small {
245
    min-height: @input-height-small;
246
247
248
    padding: @padding-small;
    font-size: @font-size-small;
    border-radius: @border-radius-small;
249
250
  }
}
251

Mark Otto's avatar
Mark Otto committed
252
253
254
255
256


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

257
// Grid style input sizes
258
259
input[class*="span"],
select[class*="span"],
260
textarea[class*="span"] {
Mark Otto's avatar
Mark Otto committed
261
262
263
  float: none;
  margin-left: 0;
  margin-right: 0;
264
}
Mark Otto's avatar
Mark Otto committed
265

266
267
// Ensure input-prepend/append never wraps
.input-append input[class*="span"],
268
.input-prepend input[class*="span"] {
269
270
  display: inline-block;
}
271

272
273
input[class*="span"],
select[class*="span"],
274
textarea[class*="span"] {
275
  height: @input-height-base;
276
}
277

278

279
280
281

// DISABLED STATE
// --------------
282

283
// Disabled and read-only inputs
284
285
286
// 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.
287
288
289
290
291
292
293
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
294
    background-color: @input-bg-disabled;
295
  }
Jacob Thornton's avatar
Jacob Thornton committed
296
}
297
// Explicitly reset the colors here
298
299
300
301
302
303
304
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
305
}
Jacob Thornton's avatar
Jacob Thornton committed
306

307
308


309

310
311
// FORM FIELD FEEDBACK STATES
// --------------------------
312

313
// Warning
314
.has-warning {
315
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-bg);
316
317
}
// Error
318
.has-error {
319
  .formFieldState(@state-danger-text, @state-danger-text, @state-danger-bg);
320
321
}
// Success
322
.has-success {
323
  .formFieldState(@state-success-text, @state-success-text, @state-success-bg);
324
}
325

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

340
341
342
343
344
345


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

.form-actions {
346
347
348
  padding: (@line-height-base - 1) 20px @line-height-base;
  margin-top: @line-height-base;
  margin-bottom: @line-height-base;
349
  background-color: @form-actions-bg;
350
  border-top: 1px solid #e5e5e5;
351
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
352
353
}

354
355


356
357
358
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
359
360
.help-block,
.help-inline {
Mark Otto's avatar
Mark Otto committed
361
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
362
363
}

364
.help-block {
365
  display: block; // account for any element using help-block
366
  margin-bottom: (@line-height-base / 2);
Jacob Thornton's avatar
Jacob Thornton committed
367
}
368

Jacob Thornton's avatar
Jacob Thornton committed
369
.help-inline {
370
371
  display: inline-block;
  vertical-align: middle;
372
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
373
}
374

375

376

Mark Otto's avatar
Mark Otto committed
377
378
// Input groups
// --------------------------------------------------
379

Mark Otto's avatar
Mark Otto committed
380
381
382
383
// Base styles
// -------------------------
.input-group {
  display: table;
384

Mark Otto's avatar
Mark Otto committed
385
386
387
388
  // Undo padding and float of grid classes
  &[class*="span"] {
    float: none;
    padding: 0;
389
  }
390

391
  input,
392
  select {
Mark Otto's avatar
Mark Otto committed
393
    width: 100%;
394
395
  }
}
396

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

Mark Otto's avatar
Mark Otto committed
419
420
421
422
423
424
425
426
427
428
// 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;
429
  background-color: @gray-lighter;
Mark Otto's avatar
Mark Otto committed
430
  border: 1px solid #ccc;
431
432
433
434
435
436

	&.input-small {
	  padding: @padding-small;
	  font-size: @font-size-small;
  }
	&.input-large {
437
		padding: @padding-large;
438
439
		font-size: @font-size-large;
	}
440
}
Mark Otto's avatar
Mark Otto committed
441
442
443
444
445

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

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

// 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); }
498
  }
499
500
501
502
503
504
505
506
507
508
}

// 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); }
509
  }
510
}
Mark Otto's avatar
Mark Otto committed
511
512
513
514
515
516



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

517
@media screen and (min-width: @screen-tablet) {
Mark Otto's avatar
Mark Otto committed
518
519

  .form-horizontal {
520

Mark Otto's avatar
Mark Otto committed
521
522
523
524
    // Increase spacing between groups
    .control-group {
      position: relative;
      margin-bottom: @line-height-base;
525
      .clearfix();
Mark Otto's avatar
Mark Otto committed
526
527
528

      input,
      select,
529
      textarea {
Mark Otto's avatar
Mark Otto committed
530
531
        margin-bottom: 0;
      }
532
    }
Mark Otto's avatar
Mark Otto committed
533

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

Mark Otto's avatar
Mark Otto committed
542
543
544
545
    // Move over all input controls and content over
    .control-group > .controls {
      margin-left: @component-offset-horizontal;
    }
Mark Otto's avatar
Mark Otto committed
546

547
548
549
550
551
    // Make sure form actions buttons are aligned with controls
    .form-actions {
      padding-left: @component-offset-horizontal;
    }

Mark Otto's avatar
Mark Otto committed
552
  }
Mark Otto's avatar
Mark Otto committed
553
}