forms.less 11.4 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;
70
71
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  .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 */
121
    .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
122
  }
123
}
124

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

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

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

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

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

160

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

// Make uneditable inputs look inactive
.uneditable-input,
.uneditable-textarea {
  color: @grayLight;
168
169
  background-color: darken(@input-background, 1%);
  border-color: @input-border;
Mark Otto's avatar
Mark Otto committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  .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
// -------------------------

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

196

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

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

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

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

238
239


240
241
242
// INPUT SIZES
// -----------

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

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


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

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

.controls-row {
Mark Otto's avatar
Mark Otto committed
295
  #grid > .input(@grid-column-width, @grid-gutter-width, @grid-row-width);
Mark Otto's avatar
Mark Otto committed
296
297
}

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

306
307
308
309
input[class*="span"],
select[class*="span"],
textarea[class*="span"],
.uneditable-input[class*="span"] {
310
  height: @input-height;
311
}
312
313
314
315
// Control row for multiple inputs per line
.controls-row {
  .clearfix(); // Clear the float from controls
}
316
317

// Float to collapse white-space for proper grid alignment
Mark Otto's avatar
Mark Otto committed
318
.controls-row [class*="span"] {
319
  float: left;
320
}
321
322
323
324
325
// Explicity set top padding on all checkboxes/radios, not just first-child
.controls-row .checkbox[class*="span"],
.controls-row .radio[class*="span"] {
  padding-top: 5px;
}
326
327


328

329
330
331

// DISABLED STATE
// --------------
332

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

357
358


359

360
361
// FORM FIELD FEEDBACK STATES
// --------------------------
362

363
// Warning
364
.control-group.warning {
Mark Otto's avatar
Mark Otto committed
365
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-background);
366
367
368
}
// Error
.control-group.error {
Mark Otto's avatar
Mark Otto committed
369
  .formFieldState(@state-error-text, @state-error-text, @state-error-background);
370
371
}
// Success
372
.control-group.success {
Mark Otto's avatar
Mark Otto committed
373
  .formFieldState(@state-success-text, @state-success-text, @state-success-background);
374
}
375
376
// Success
.control-group.info {
Mark Otto's avatar
Mark Otto committed
377
  .formFieldState(@state-info-text, @state-info-text, @state-info-background);
378
}
379

380
381
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
382
383
384
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
385
386
387
388
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
389
390
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
391
392
393
  }
}

394
395
396
397
398
399


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

.form-actions {
400
401
402
  padding: (@line-height-base - 1) 20px @line-height-base;
  margin-top: @line-height-base;
  margin-bottom: @line-height-base;
403
  background-color: @form-actions-background;
404
  border-top: 1px solid #e5e5e5;
405
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
406
407
}

408
409


410
411
412
// HELP TEXT
// ---------

Mark Otto's avatar
Mark Otto committed
413
414
.help-block,
.help-inline {
Mark Otto's avatar
Mark Otto committed
415
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Mark Otto's avatar
Mark Otto committed
416
417
}

418
.help-block {
419
  display: block; // account for any element using help-block
420
  margin-bottom: @line-height-base / 2;
Jacob Thornton's avatar
Jacob Thornton committed
421
}
422

Jacob Thornton's avatar
Jacob Thornton committed
423
.help-inline {
424
425
  display: inline-block;
  vertical-align: middle;
426
  padding-left: 5px;
Jacob Thornton's avatar
Jacob Thornton committed
427
}
428

429

430

Mark Otto's avatar
Mark Otto committed
431

Mark Otto's avatar
Mark Otto committed
432
433
// Input groups
// --------------------------------------------------
434

Mark Otto's avatar
Mark Otto committed
435
436
437
438
// Base styles
// -------------------------
.input-group {
  display: table;
439

Mark Otto's avatar
Mark Otto committed
440
441
442
443
  // Undo padding and float of grid classes
  &[class*="span"] {
    float: none;
    padding: 0;
444
  }
445

446
  input,
447
  select,
448
  .uneditable-input {
Mark Otto's avatar
Mark Otto committed
449
    width: 100%;
450
451
  }
}
452

Mark Otto's avatar
Mark Otto committed
453
454
455
456
457
458
459
460
461
// 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
462
}
Mark Otto's avatar
Mark Otto committed
463
464
465
466
467
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
468
469
}

Mark Otto's avatar
Mark Otto committed
470
471
472
473
474
475
476
477
478
479
480
481
// 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;
482
}
Mark Otto's avatar
Mark Otto committed
483
484
485
486
487
488

// 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);
489
}
Mark Otto's avatar
Mark Otto committed
490
491
.input-group-addon:first-child {
  border-right: 0;
492
}
Mark Otto's avatar
Mark Otto committed
493
494
495
496
.input-group input:last-child,
.input-group .uneditable-input:last-child,
.input-group-addon:last-child {
  .border-right-radius(@border-radius-base);
497
}
Mark Otto's avatar
Mark Otto committed
498
499
.input-group-addon:last-child {
  border-left: 0;
500
501
}

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