forms.less 10.1 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;
Mark Otto's avatar
Mark Otto committed
23
  margin-bottom: @line-height-computed;
24
  font-size: (@font-size-base * 1.5);
Mark Otto's avatar
Mark Otto committed
25
  line-height: @line-height-headings;
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: 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
61
  font-size: @font-size-base;
  line-height: @line-height-base;
62
  color: @gray;
63
  vertical-align: middle;
64
  background-color: @input-bg;
65
66
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
Mark Otto's avatar
Mark Otto committed
67
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
68
  .transition(~"border-color linear .2s, box-shadow linear .2s");
69
70
}

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

79
80
81
82
83
84
85
86
87
88
89
// 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
}

90
91
92
93
94
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

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

Mark Otto's avatar
Mark Otto committed
100
// Everything else
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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"],
115
input[type="color"] {
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-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
139
}
140

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

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

155

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

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

165

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

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
172
  display: block;
Mark Otto's avatar
Mark Otto committed
173
  min-height: @line-height-computed; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
174
175
  margin-top: 10px;
  margin-bottom: 10px;
176
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
177
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
178
179
180
181
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
182
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
183
  }
184
}
185
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
186
187
188
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
189
  float: left;
190
  margin-left: -20px;
191
}
Mark Otto's avatar
Mark Otto committed
192
193
.radio + .radio,
.checkbox + .checkbox {
Mark Otto's avatar
Mark Otto committed
194
  margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
Mark Otto committed
195
}
196

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

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

222
223


224
225
226
// INPUT SIZES
// -----------

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

Mark Otto's avatar
Mark Otto committed
256

257
258
// DISABLED STATE
// --------------
259

260
// Disabled and read-only inputs
261
262
263
// 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.
264
265
266
267
268
269
270
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
271
    background-color: @input-bg-disabled;
272
  }
Jacob Thornton's avatar
Jacob Thornton committed
273
}
274
// Explicitly reset the colors here
275
276
277
278
279
280
281
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
282
}
Jacob Thornton's avatar
Jacob Thornton committed
283

284
285


286

287
288
// FORM FIELD FEEDBACK STATES
// --------------------------
289

290
// Warning
291
.has-warning {
292
  .formFieldState(@state-warning-text, @state-warning-text, @state-warning-bg);
293
294
}
// Error
295
.has-error {
296
  .formFieldState(@state-danger-text, @state-danger-text, @state-danger-bg);
297
298
}
// Success
299
.has-success {
300
  .formFieldState(@state-success-text, @state-success-text, @state-success-bg);
301
}
302

303
304
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
305
306
307
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
308
309
310
311
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
312
313
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
314
315
316
  }
}

317
318
319
320
321
322


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

.form-actions {
Mark Otto's avatar
Mark Otto committed
323
324
325
  padding: @line-height-computed 20px;
  margin-top: @line-height-computed;
  margin-bottom: @line-height-computed;
326
  background-color: @form-actions-bg;
327
  border-top: 1px solid #e5e5e5;
328
  .clearfix(); // Adding clearfix to allow for .pull-right button containers
Jacob Thornton's avatar
Jacob Thornton committed
329
330
}

331
332


333
334
335
// HELP TEXT
// ---------

336
.help-block {
337
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
338
339
340
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
341
}
342

343

344

Mark Otto's avatar
Mark Otto committed
345
346
// Input groups
// --------------------------------------------------
347

Mark Otto's avatar
Mark Otto committed
348
349
350
351
// Base styles
// -------------------------
.input-group {
  display: table;
352

Mark Otto's avatar
Mark Otto committed
353
  // Undo padding and float of grid classes
Mark Otto's avatar
Mark Otto committed
354
  &.col {
Mark Otto's avatar
Mark Otto committed
355
    float: none;
Mark Otto's avatar
Mark Otto committed
356
357
    padding-left: 0;
    padding-right: 0;
358
  }
359

360
  input,
361
  select {
Mark Otto's avatar
Mark Otto committed
362
    width: 100%;
Mark Otto's avatar
Mark Otto committed
363
    margin-bottom: 0;
364
365
  }
}
366

Mark Otto's avatar
Mark Otto committed
367
368
369
370
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
371
.input-group input {
Mark Otto's avatar
Mark Otto committed
372
  display: table-cell;
373
374

  &:not(:first-child):not(:last-child) {
375
376
    border-radius: 0;
  }
Jacob Thornton's avatar
Jacob Thornton committed
377
}
Mark Otto's avatar
Mark Otto committed
378
379
380
381
382
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
383
384
}

Mark Otto's avatar
Mark Otto committed
385
386
387
388
389
390
391
392
393
394
// 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;
395
  background-color: @gray-lighter;
Mark Otto's avatar
Mark Otto committed
396
  border: 1px solid #ccc;
397
  border-radius: @border-radius-base;
398

Mark Otto's avatar
Mark Otto committed
399
400
401
  &.input-small {
    padding: @padding-small;
    font-size: @font-size-small;
402
    border-radius: @border-radius-small;  }
Mark Otto's avatar
Mark Otto committed
403
404
405
  &.input-large {
    padding: @padding-large;
    font-size: @font-size-large;
406
    border-radius: @border-radius-large;
407
  }
408
}
Mark Otto's avatar
Mark Otto committed
409
410
411

// Reset rounded corners
.input-group input:first-child,
412
.input-group-addon:first-child,
413
414
415
.input-group-btn:first-child > .btn,
.input-group-btn:first-child > .dropdown-toggle,
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle) {
416
  .border-right-radius(0);
417
}
Mark Otto's avatar
Mark Otto committed
418
419
.input-group-addon:first-child {
  border-right: 0;
420
}
Mark Otto's avatar
Mark Otto committed
421
.input-group input:last-child,
422
.input-group-addon:last-child,
423
424
425
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child) {
426
  .border-left-radius(0);
427
}
Mark Otto's avatar
Mark Otto committed
428
429
.input-group-addon:last-child {
  border-left: 0;
430
431
}

Mark Otto's avatar
Mark Otto committed
432
433
// Button input groups
// -------------------------
434
435
.input-group-btn {
  position: relative;
Mark Otto's avatar
Mark Otto committed
436
  white-space: nowrap;
437
}
Mark Otto's avatar
Mark Otto committed
438
.input-group-btn > .btn {
439
  position: relative;
Mark Otto's avatar
Mark Otto committed
440
441
  float: left; // Collapse white-space
  + .btn {
442
    margin-left: -1px;
443
  }
444
445
446
447
  // Bring the "active" button to the front
  &:hover,
  &:active {
    z-index: 2;
448
  }
Mark Otto's avatar
Mark Otto committed
449
}
450

Mark Otto's avatar
Mark Otto committed
451

Mark Otto's avatar
Mark Otto committed
452
453
454
455
456
457
458
459
460
461
// Inline forms
// --------------------------------------------------

.form-inline {
  input,
  select,
  textarea,
  .radio,
  .checkbox {
    display: inline-block;
Mark Otto's avatar
Mark Otto committed
462
463
464
465
  }
  .radio,
  .checkbox {
    margin-top: 0;
Mark Otto's avatar
Mark Otto committed
466
467
468
469
470
    margin-bottom: 0;
  }
}


Mark Otto's avatar
Mark Otto committed
471
472
// Horizontal forms
// --------------------------------------------------
Mark Otto's avatar
Mark Otto committed
473
// Horizontal forms are built on grid classes.
Mark Otto's avatar
Mark Otto committed
474

Mark Otto's avatar
Mark Otto committed
475
476
477
478
479
480
.form-horizontal {
  .row + .row {
    margin-top: 15px;
  }
  .row-label {
    padding-top: 6px;
481
482
483
484
485
486
  }
}

// Only right aline form labels here when the columns stop stacking
@media (min-width: 768px) {
  .form-horizontal .row-label {
Mark Otto's avatar
Mark Otto committed
487
    text-align: right;
Mark Otto's avatar
Mark Otto committed
488
  }
Mark Otto's avatar
Mark Otto committed
489
}