forms.less 11.5 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 {
10
  margin: 0 0 @line-height-base;
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 {
58
  display: inline-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
206
  padding-left: 20px;
207
}
208
209
.radio label,
.checkbox label {
Mark Otto's avatar
Mark Otto committed
210
  margin-bottom: 0;
211
212
  font-weight: normal;
}
213
214
.radio input[type="radio"],
.checkbox input[type="checkbox"] {
215
  float: left;
216
  margin-left: -20px;
217
218
219
220
221
}

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

225
// Radios and checkboxes on same line
226
// TODO v3: Convert .inline to .control-inline
227
228
229
.radio.inline,
.checkbox.inline {
  display: inline-block;
230
  padding-top: 5px;
231
  margin-bottom: 0;
232
  vertical-align: middle;
233
234
235
}
.radio.inline + .radio.inline,
.checkbox.inline + .checkbox.inline {
236
  margin-left: 10px; // space out consecutive inline controls
237
238
}

239
240


241
242
243
// INPUT SIZES
// -----------

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
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 {
262
    padding: @padding-large;
263
264
    padding-left: 14px;
    padding-right: 14px; // TODO: Resolve this override
265
266
    font-size: @font-size-large;
    border-radius: @border-radius-large;
267
268
  }
  &.input-small {
269
270
271
    padding: @padding-small;
    font-size: @font-size-small;
    border-radius: @border-radius-small;
272
273
  }
  &.input-mini {
274
275
276
    padding: @padding-mini;
    font-size: @font-size-mini;
    border-radius: @border-radius-small;
277
278
  }
}
279

Mark Otto's avatar
Mark Otto committed
280
281
282
283
284


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

285
// Grid style input sizes
286
287
288
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
Mark Otto's avatar
Mark Otto committed
289
290
291
292
.uneditable-input[class*="span"] {
  float: none;
  margin-left: 0;
  margin-right: 0;
293
}
Mark Otto's avatar
Mark Otto committed
294

295
296
297
298
// 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
299
.input-prepend .uneditable-input[class*="span"] {
300
301
  display: inline-block;
}
302

303
304
305
306
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
.uneditable-input[class*="span"] {
307
  height: @input-height;
308
}
309

310

311
312
313

// DISABLED STATE
// --------------
314

315
// Disabled and read-only inputs
316
317
318
// 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.
319
320
321
322
323
324
325
326
327
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-background-disabled;
  }
Jacob Thornton's avatar
Jacob Thornton committed
328
}
329
// Explicitly reset the colors here
330
331
332
333
334
335
336
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
337
}
Jacob Thornton's avatar
Jacob Thornton committed
338

339
340


341

342
343
// FORM FIELD FEEDBACK STATES
// --------------------------
344

345
// Warning
346
.has-warning {
Mark Otto's avatar
Mark Otto committed
347
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-background);
348
349
}
// Error
350
.has-error {
Mark Otto's avatar
Mark Otto committed
351
  .formFieldState(@state-error-text, @state-error-text, @state-error-background);
352
353
}
// Success
354
.has-success {
Mark Otto's avatar
Mark Otto committed
355
  .formFieldState(@state-success-text, @state-success-text, @state-success-background);
356
}
357

358
359
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
360
361
362
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
363
364
365
366
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
367
368
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
369
370
371
  }
}

372
373
374
375
376
377


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

.form-actions {
378
379
380
  padding: (@line-height-base - 1) 20px @line-height-base;
  margin-top: @line-height-base;
  margin-bottom: @line-height-base;
381
  background-color: @form-actions-background;
382
  border-top: 1px solid #e5e5e5;
383
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
384
385
}

386
387


388
389
390
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
391
392
.help-block,
.help-inline {
Mark Otto's avatar
Mark Otto committed
393
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
394
395
}

396
.help-block {
397
  display: block; // account for any element using help-block
398
  margin-bottom: @line-height-base / 2;
Jacob Thornton's avatar
Jacob Thornton committed
399
}
400

Jacob Thornton's avatar
Jacob Thornton committed
401
.help-inline {
402
403
  display: inline-block;
  vertical-align: middle;
404
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
405
}
406

407

408

Mark Otto's avatar
Mark Otto committed
409
410
// Input groups
// --------------------------------------------------
411

Mark Otto's avatar
Mark Otto committed
412
413
414
415
// Base styles
// -------------------------
.input-group {
  display: table;
416

Mark Otto's avatar
Mark Otto committed
417
418
419
420
  // Undo padding and float of grid classes
  &[class*="span"] {
    float: none;
    padding: 0;
421
  }
422

423
  input,
424
  select,
425
  .uneditable-input {
Mark Otto's avatar
Mark Otto committed
426
    width: 100%;
427
428
  }
}
429

Mark Otto's avatar
Mark Otto committed
430
431
432
433
434
435
436
437
438
// 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
439
}
Mark Otto's avatar
Mark Otto committed
440
441
442
443
444
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
445
446
}

Mark Otto's avatar
Mark Otto committed
447
448
449
450
451
452
453
454
455
456
457
458
// 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;
459
}
Mark Otto's avatar
Mark Otto committed
460
461
462
463
464
465

// 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);
466
}
Mark Otto's avatar
Mark Otto committed
467
468
.input-group-addon:first-child {
  border-right: 0;
469
}
Mark Otto's avatar
Mark Otto committed
470
471
472
473
.input-group input:last-child,
.input-group .uneditable-input:last-child,
.input-group-addon:last-child {
  .border-right-radius(@border-radius-base);
474
}
Mark Otto's avatar
Mark Otto committed
475
476
.input-group-addon:last-child {
  border-left: 0;
477
478
}

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



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

.form-horizontal {

  // Increase spacing between groups
  .control-group {
527
528
    position: relative;
    margin-bottom: @line-height-base;
Mark Otto's avatar
Mark Otto committed
529
    .clearfix();
530
531
532
533
534
535
536

    input,
    select,
    textarea,
    .uneditable-input {
      margin-bottom: 0;
    }
Mark Otto's avatar
Mark Otto committed
537
538
539
540
541
542
  }

  // Float the labels left
  .control-group > .control-label {
    float: left;
    width: @component-offset-horizontal - 20;
543
    padding-top: 6px;
Mark Otto's avatar
Mark Otto committed
544
545
546
547
548
549
550
551
552
    text-align: right;
  }

  // Move over all input controls and content over
  .control-group > .controls {
    margin-left: @component-offset-horizontal;
  }

}