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

Mark Otto's avatar
Mark Otto committed
196
/*
197
198
199
// Move the options list down to align with labels
.controls > .radio:first-child,
.controls > .checkbox:first-child {
200
  padding-top: 5px; // has to be padding because margin collaspes
201
}
Mark Otto's avatar
Mark Otto committed
202
*/
203

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

220
221


222
223
224
// INPUT SIZES
// -----------

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

Mark Otto's avatar
Mark Otto committed
254
255
256
257
258


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

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

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

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

280

281
282
283

// DISABLED STATE
// --------------
284

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

309
310


311

312
313
// FORM FIELD FEEDBACK STATES
// --------------------------
314

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

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

342
343
344
345
346
347


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

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

356
357


358
359
360
// HELP TEXT
// ---------

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

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

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

377

378

Mark Otto's avatar
Mark Otto committed
379
380
// Input groups
// --------------------------------------------------
381

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

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

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

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

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

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

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

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

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

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



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

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

  .form-horizontal {
522

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
554
  }
Mark Otto's avatar
Mark Otto committed
555
}