forms.less 11.8 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
24
25
  margin-bottom: @line-height-base;
  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
57
input[type="color"],
.uneditable-input {
Mark Otto's avatar
Mark Otto committed
58
  display: block;
59
  .box-sizing(border-box); // Makes inputs behave like true block-level elements
60
  min-height: @input-height; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
61
  padding: 6px 9px;
62
63
64
  margin-bottom: @line-height-base / 2;
  font-size: @font-size-base;
  line-height: @line-height-base;
65
  color: @gray;
66
  vertical-align: middle;
67
68
69
  background-color: @input-background;
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
Mark Otto's avatar
Mark Otto committed
70
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
71
  .transition(~"border linear .2s, box-shadow linear .2s");
72
73
}

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

83
84
85
86
87
88
89
90
91
92
93
// 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
}

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

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

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

134
// Set the height of select and file controls to match text inputs
135
select,
136
input[type="file"] {
137
138
  height: @input-height; /* 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;
Mark Otto's avatar
Mark Otto committed
139
}
140

Mark Otto's avatar
Mark Otto committed
141
// Make select elements obey height by applying a border
Mark Otto's avatar
Mark Otto committed
142
// TODO: See if this can be part of the above selector stack
Mark Otto's avatar
Mark Otto committed
143
select {
144
  border: 1px solid @input-border;
Mark Otto's avatar
Mark Otto committed
145
146
}

Mark Otto's avatar
Mark Otto committed
147
// Make multiple select elements height not fixed
148
149
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
150
  height: auto;
Mark Otto's avatar
Mark Otto committed
151
152
}

153
154
155
156
157
158
159
// Focus for select, file, radio, and checkbox
select:focus,
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
160

161

Mark Otto's avatar
Mark Otto committed
162
163
164
165
166
167
168
// Uneditable inputs
// -------------------------

// Make uneditable inputs look inactive
.uneditable-input,
.uneditable-textarea {
  color: @grayLight;
169
170
  background-color: darken(@input-background, 1%);
  border-color: @input-border;
Mark Otto's avatar
Mark Otto committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  cursor: not-allowed;
}

// For text that needs to appear as an input but should not be an input
.uneditable-input {
  overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  white-space: nowrap;
}

// Make uneditable textareas behave like a textarea
.uneditable-textarea {
  width: auto;
  height: auto;
}


// Placeholder
// -------------------------

191
// 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
192
193
194
195
196
input,
textarea {
  .placeholder();
}

197

198
199
200
201
202
203
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
204
  display: block;
205
  min-height: @line-height-base; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
206
  margin-bottom: @line-height-base / 2;
207
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
208
209
210
211
212
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
  }
213
}
Mark Otto's avatar
Mark Otto committed
214

215
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
216
217
218
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
219
  float: left;
220
  margin-left: -20px;
221
}
Mark Otto's avatar
Mark Otto committed
222
223
224
225
.radio + .radio,
.checkbox + .checkbox {
  margin-top: (@line-height-base / 4) * -1;
}
226
227
228
229

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

233
// Radios and checkboxes on same line
234
// TODO v3: Convert .inline to .control-inline
Mark Otto's avatar
Mark Otto committed
235
236
.radio-inline,
.checkbox-inline {
237
  display: inline-block;
238
  padding-top: 5px;
Mark Otto's avatar
Mark Otto committed
239
  padding-left: 20px;
240
  margin-bottom: 0;
241
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
242
  font-weight: normal;
243
}
Mark Otto's avatar
Mark Otto committed
244
245
246
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
247
  margin-left: 10px; // space out consecutive inline controls
248
249
}

250
251


252
253
254
// INPUT SIZES
// -----------

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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"],
input[type="color"],
.uneditable-input {
  &.input-large {
273
    padding: @padding-large;
274
275
    padding-left: 14px;
    padding-right: 14px; // TODO: Resolve this override
276
277
    font-size: @font-size-large;
    border-radius: @border-radius-large;
278
279
  }
  &.input-small {
280
281
282
    padding: @padding-small;
    font-size: @font-size-small;
    border-radius: @border-radius-small;
283
284
  }
  &.input-mini {
285
286
287
    padding: @padding-mini;
    font-size: @font-size-mini;
    border-radius: @border-radius-small;
288
289
  }
}
290

Mark Otto's avatar
Mark Otto committed
291
292
293
294
295


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

296
// Grid style input sizes
297
298
299
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
Mark Otto's avatar
Mark Otto committed
300
301
302
303
.uneditable-input[class*="span"] {
  float: none;
  margin-left: 0;
  margin-right: 0;
304
}
Mark Otto's avatar
Mark Otto committed
305

306
307
308
309
// Ensure input-prepend/append never wraps
.input-append input[class*="span"],
.input-append .uneditable-input[class*="span"],
.input-prepend input[class*="span"],
Mark Otto's avatar
Mark Otto committed
310
.input-prepend .uneditable-input[class*="span"] {
311
312
  display: inline-block;
}
313

314
315
316
317
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
.uneditable-input[class*="span"] {
318
  height: @input-height;
319
}
320

321

322
323
324

// DISABLED STATE
// --------------
325

326
// Disabled and read-only inputs
327
328
329
// 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.
330
331
332
333
334
335
336
337
338
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-background-disabled;
  }
Jacob Thornton's avatar
Jacob Thornton committed
339
}
340
// Explicitly reset the colors here
341
342
343
344
345
346
347
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
348
}
Jacob Thornton's avatar
Jacob Thornton committed
349

350
351


352

353
354
// FORM FIELD FEEDBACK STATES
// --------------------------
355

356
// Warning
357
.has-warning {
Mark Otto's avatar
Mark Otto committed
358
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-background);
359
360
}
// Error
361
.has-error {
Mark Otto's avatar
Mark Otto committed
362
  .formFieldState(@state-error-text, @state-error-text, @state-error-background);
363
364
}
// Success
365
.has-success {
Mark Otto's avatar
Mark Otto committed
366
  .formFieldState(@state-success-text, @state-success-text, @state-success-background);
367
}
368

369
370
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
371
372
373
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
374
375
376
377
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
378
379
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
380
381
382
  }
}

383
384
385
386
387
388


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

.form-actions {
389
390
391
  padding: (@line-height-base - 1) 20px @line-height-base;
  margin-top: @line-height-base;
  margin-bottom: @line-height-base;
392
  background-color: @form-actions-background;
393
  border-top: 1px solid #e5e5e5;
Mark Otto's avatar
Mark Otto committed
394
  .clear_float(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
395
396
}

397
398


399
400
401
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
402
403
.help-block,
.help-inline {
Mark Otto's avatar
Mark Otto committed
404
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
405
406
}

407
.help-block {
408
  display: block; // account for any element using help-block
409
  margin-bottom: @line-height-base / 2;
Jacob Thornton's avatar
Jacob Thornton committed
410
}
411

Jacob Thornton's avatar
Jacob Thornton committed
412
.help-inline {
413
414
  display: inline-block;
  vertical-align: middle;
415
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
416
}
417

418

419

Mark Otto's avatar
Mark Otto committed
420
421
// Input groups
// --------------------------------------------------
422

Mark Otto's avatar
Mark Otto committed
423
424
425
426
// Base styles
// -------------------------
.input-group {
  display: table;
427

Mark Otto's avatar
Mark Otto committed
428
429
430
431
  // Undo padding and float of grid classes
  &[class*="span"] {
    float: none;
    padding: 0;
432
  }
433

434
  input,
435
  select,
436
  .uneditable-input {
Mark Otto's avatar
Mark Otto committed
437
    width: 100%;
438
439
  }
}
440

Mark Otto's avatar
Mark Otto committed
441
442
443
444
445
446
447
448
449
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
.input-group input,
.input-group .uneditable-input {
  display: table-cell;
  margin: 0;
  border-radius: 0;
Jacob Thornton's avatar
Jacob Thornton committed
450
}
Mark Otto's avatar
Mark Otto committed
451
452
453
454
455
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
456
457
}

Mark Otto's avatar
Mark Otto committed
458
459
460
461
462
463
464
465
466
467
468
469
// 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;
470
}
Mark Otto's avatar
Mark Otto committed
471
472
473
474
475
476

// Reset rounded corners
.input-group input:first-child,
.input-group .uneditable-input:first-child,
.input-group-addon:first-child {
  .border-left-radius(@border-radius-base);
477
}
Mark Otto's avatar
Mark Otto committed
478
479
.input-group-addon:first-child {
  border-right: 0;
480
}
Mark Otto's avatar
Mark Otto committed
481
482
483
484
.input-group input:last-child,
.input-group .uneditable-input:last-child,
.input-group-addon:last-child {
  .border-right-radius(@border-radius-base);
485
}
Mark Otto's avatar
Mark Otto committed
486
487
.input-group-addon:last-child {
  border-left: 0;
488
489
}

Mark Otto's avatar
Mark Otto committed
490
491
492
493
494
// Button input groups
// -------------------------
.input-group-btn,
.input-group-btn .btn {
  white-space: nowrap;
495
}
Mark Otto's avatar
Mark Otto committed
496
497
498
499
500
.input-group-btn > .btn {
  float: left; // Collapse white-space
  border-radius: 0;
  + .btn {
    border-left: 0;
501
  }
Mark Otto's avatar
Mark Otto committed
502
}
Mark Otto's avatar
Mark Otto committed
503
504
.input-group-btn.btn-group {
  display: table-cell;
505
}
Mark Otto's avatar
Mark Otto committed
506
507
// Prepend
.input-group-btn {
508
  &:first-child > .btn,
Mark Otto's avatar
Mark Otto committed
509
510
  &.btn-group:first-child > .btn {
    border-right: 0;
511
  }
512
  &:first-child > .btn,
Mark Otto's avatar
Mark Otto committed
513
514
  &.btn-group:first-child > .btn {
    border-radius: @border-radius-base 0 0 @border-radius-base;
515
  }
Mark Otto's avatar
Mark Otto committed
516
517
518
}
// Append
.input-group-btn {
519
  &:last-child > .btn,
Mark Otto's avatar
Mark Otto committed
520
521
  &.btn-group:last-child > .btn:first-child {
    border-left: 0;
522
  }
523
  &:last-child > .btn,
Mark Otto's avatar
Mark Otto committed
524
525
  &.btn-group:last-child > .btn {
    border-radius: 0 @border-radius-base @border-radius-base 0;
526
  }
527
}
Mark Otto's avatar
Mark Otto committed
528
529
530
531
532
533
534



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


Mark Otto's avatar
Mark Otto committed
535
536
537
@media screen and (min-width: 768px) {

  .form-horizontal {
538

Mark Otto's avatar
Mark Otto committed
539
540
541
542
543
544
545
546
547
548
549
550
    // Increase spacing between groups
    .control-group {
      position: relative;
      margin-bottom: @line-height-base;
      .clear_float();

      input,
      select,
      textarea,
      .uneditable-input {
        margin-bottom: 0;
      }
551
    }
Mark Otto's avatar
Mark Otto committed
552

Mark Otto's avatar
Mark Otto committed
553
554
555
556
557
558
559
    // Float the labels left
    .control-group > .control-label {
      float: left;
      width: @component-offset-horizontal - 20;
      padding-top: 6px;
      text-align: right;
    }
Mark Otto's avatar
Mark Otto committed
560

Mark Otto's avatar
Mark Otto committed
561
562
563
564
    // Move over all input controls and content over
    .control-group > .controls {
      margin-left: @component-offset-horizontal;
    }
Mark Otto's avatar
Mark Otto committed
565

Mark Otto's avatar
Mark Otto committed
566
  }
Mark Otto's avatar
Mark Otto committed
567
}