forms.less 9.85 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);
25
  line-height: inherit;
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
  height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
59
  padding: @padding-base-vertical @padding-base-horizontal;
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 ease-in-out .15s, box-shadow ease-in-out .15s");
69
70
71
72

  &:focus {
    border-color: rgba(82,168,236,.8);
    outline: 0;
73
    .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
74
  }
75
76
77
78
79
80
81
82
83
84
85

  // Disabled and read-only inputs
  // 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.
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-bg-disabled;
  }
86
87
}

Mark Otto's avatar
Mark Otto committed
88
// Reset appearance properties for textual inputs and textarea
Mark Otto's avatar
Mark Otto committed
89
// Can't be on input[type=*] selectors or it's too specific
Mark Otto's avatar
Mark Otto committed
90
input,
Mark Otto's avatar
Mark Otto committed
91
select,
92
textarea {
Mark Otto's avatar
Mark Otto committed
93
  width: 100%;
Mark Otto's avatar
Mark Otto committed
94
}
Mark Otto's avatar
Mark Otto committed
95

96
97
98
99
100
101
102
103
104
105
106
// 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
}

107
108
109
110
111
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

112
113
114
115
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
116

Mark Otto's avatar
Mark Otto committed
117
// Position radios and checkboxes better
118
119
input[type="radio"],
input[type="checkbox"] {
120
  margin: 4px 0 0;
121
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
122
  line-height: normal;
123
}
Mark Otto's avatar
Mark Otto committed
124

125
// Set the height of select and file controls to match text inputs
126
input[type="file"] {
127
128
  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
129
}
130

Mark Otto's avatar
Mark Otto committed
131
// Make multiple select elements height not fixed
132
133
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
134
  height: auto;
Mark Otto's avatar
Mark Otto committed
135
136
}

137
138
139
140
141
142
143
// Fix optgroup Firefox bug per https://github.com/twitter/bootstrap/issues/7611
select optgroup {
  font-size: inherit;
  font-style: inherit;
  font-family: inherit;
}

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

151
152
153
154
// Fix for Chrome number input
// Setting certain font-sizes causes the `I` bar to appear on hover of the bottom increment button.
// See https://github.com/twitter/bootstrap/issues/8350 for more.
input[type="number"] {
155
  &::-webkit-outer-spin-button,
156
157
158
159
160
  &::-webkit-inner-spin-button  {
    height: auto;
  }
}

161

Mark Otto's avatar
Mark Otto committed
162
163
164
// Placeholder
// -------------------------

165
// 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
166
167
168
169
170
input,
textarea {
  .placeholder();
}

171

172
173
174
175
176
177
// CHECKBOXES & RADIOS
// -------------------

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

Mark Otto's avatar
Mark Otto committed
203
/*
204
205
206
// Move the options list down to align with labels
.controls > .radio:first-child,
.controls > .checkbox:first-child {
Chris Rebert's avatar
Chris Rebert committed
207
  padding-top: 5px; // has to be padding because margin collapses
208
}
Mark Otto's avatar
Mark Otto committed
209
*/
210

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

228
229


230
231
232
// INPUT SIZES
// -----------

233
select,
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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"],
248
input[type="color"] {
249
  &.input-large {
250
    height: @input-height-large;
251
    padding: @padding-large-vertical @padding-large-horizontal;
252
253
    font-size: @font-size-large;
    border-radius: @border-radius-large;
254
255
  }
  &.input-small {
256
    height: @input-height-small;
257
    padding: @padding-small-vertical @padding-small-horizontal;
258
259
    font-size: @font-size-small;
    border-radius: @border-radius-small;
260
261
  }
}
262
263
264
265
266
267
268
269
270
271
select {
  &.input-large {
    height: @input-height-large;
    line-height: @input-height-large;
  }
  &.input-small {
    height: @input-height-small;
    line-height: @input-height-small;
  }
}
272

Mark Otto's avatar
Mark Otto committed
273

274

275
276
// FORM FIELD FEEDBACK STATES
// --------------------------
277

278
// Warning
279
.has-warning {
280
  .form-field-validation(@state-warning-text, @state-warning-text, @state-warning-bg);
281
282
}
// Error
283
.has-error {
284
  .form-field-validation(@state-danger-text, @state-danger-text, @state-danger-bg);
285
286
}
// Success
287
.has-success {
288
  .form-field-validation(@state-success-text, @state-success-text, @state-success-bg);
289
}
290
291
292
293




294
295
296
// HELP TEXT
// ---------

297
.help-block {
298
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
299
300
301
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
302
}
303

304

305

Mark Otto's avatar
Mark Otto committed
306
307
// Input groups
// --------------------------------------------------
308

Mark Otto's avatar
Mark Otto committed
309
310
311
312
// Base styles
// -------------------------
.input-group {
  display: table;
313
  border-collapse: separate; // prevent input groups from inheriting border styles from table cells when placed within a table
314

Mark Otto's avatar
Mark Otto committed
315
  // Undo padding and float of grid classes
Mark Otto's avatar
Mark Otto committed
316
  &.col {
Mark Otto's avatar
Mark Otto committed
317
    float: none;
Mark Otto's avatar
Mark Otto committed
318
319
    padding-left: 0;
    padding-right: 0;
320
  }
321

322
  input,
323
  select {
Mark Otto's avatar
Mark Otto committed
324
    width: 100%;
Mark Otto's avatar
Mark Otto committed
325
    margin-bottom: 0;
326
327
  }
}
328

Mark Otto's avatar
Mark Otto committed
329
330
331
332
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
333
.input-group input {
Mark Otto's avatar
Mark Otto committed
334
  display: table-cell;
335
336

  &:not(:first-child):not(:last-child) {
337
338
    border-radius: 0;
  }
Jacob Thornton's avatar
Jacob Thornton committed
339
}
Mark Otto's avatar
Mark Otto committed
340
341
342
343
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
344
  white-space: nowrap;
Mark Otto's avatar
Mark Otto committed
345
  vertical-align: middle; // Match the inputs
346
347
}

Mark Otto's avatar
Mark Otto committed
348
349
350
351
// Text input groups
// -------------------------
.input-group-addon {
  .box-sizing(border-box);
352
  padding: @padding-base-vertical @padding-base-horizontal;
Mark Otto's avatar
Mark Otto committed
353
354
355
356
357
  font-size: @font-size-base;
  font-weight: normal;
  line-height: @line-height-base;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
358
  background-color: @gray-lighter;
Mark Otto's avatar
Mark Otto committed
359
  border: 1px solid #ccc;
360
  border-radius: @border-radius-base;
361

Mark Otto's avatar
Mark Otto committed
362
  &.input-small {
363
    padding: @padding-small-vertical @padding-small-horizontal;
Mark Otto's avatar
Mark Otto committed
364
    font-size: @font-size-small;
365
366
    border-radius: @border-radius-small;
  }
Mark Otto's avatar
Mark Otto committed
367
  &.input-large {
368
    padding: @padding-large-vertical @padding-large-horizontal;
Mark Otto's avatar
Mark Otto committed
369
    font-size: @font-size-large;
370
    border-radius: @border-radius-large;
371
  }
372
}
Mark Otto's avatar
Mark Otto committed
373
374
375

// Reset rounded corners
.input-group input:first-child,
376
.input-group-addon:first-child,
377
378
379
.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) {
380
  .border-right-radius(0);
381
}
Mark Otto's avatar
Mark Otto committed
382
383
.input-group-addon:first-child {
  border-right: 0;
384
}
Mark Otto's avatar
Mark Otto committed
385
.input-group input:last-child,
386
.input-group-addon:last-child,
387
388
389
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child) {
390
  .border-left-radius(0);
391
}
Mark Otto's avatar
Mark Otto committed
392
393
.input-group-addon:last-child {
  border-left: 0;
394
395
}

Mark Otto's avatar
Mark Otto committed
396
397
// Button input groups
// -------------------------
398
399
.input-group-btn {
  position: relative;
Mark Otto's avatar
Mark Otto committed
400
  white-space: nowrap;
401
}
Mark Otto's avatar
Mark Otto committed
402
.input-group-btn > .btn {
403
  position: relative;
404
  // Jankily prevent input button groups from wrapping
Mark Otto's avatar
Mark Otto committed
405
  + .btn {
406
    margin-left: -4px;
407
  }
408
409
410
411
  // Bring the "active" button to the front
  &:hover,
  &:active {
    z-index: 2;
412
  }
Mark Otto's avatar
Mark Otto committed
413
}
414

Mark Otto's avatar
Mark Otto committed
415

Mark Otto's avatar
Mark Otto committed
416
417
418
419
420
421
422
423
424
425
// Inline forms
// --------------------------------------------------

.form-inline {
  input,
  select,
  textarea,
  .radio,
  .checkbox {
    display: inline-block;
Mark Otto's avatar
Mark Otto committed
426
427
428
429
  }
  .radio,
  .checkbox {
    margin-top: 0;
Mark Otto's avatar
Mark Otto committed
430
431
432
433
434
    margin-bottom: 0;
  }
}


Mark Otto's avatar
Mark Otto committed
435
436
// Horizontal forms
// --------------------------------------------------
Mark Otto's avatar
Mark Otto committed
437
// Horizontal forms are built on grid classes.
Mark Otto's avatar
Mark Otto committed
438

Mark Otto's avatar
Mark Otto committed
439
440
441
442
.form-horizontal {
  .row + .row {
    margin-top: 15px;
  }
443
  .control-label {
Mark Otto's avatar
Mark Otto committed
444
    padding-top: 6px;
445
446
447
  }
}

Chris Rebert's avatar
Chris Rebert committed
448
// Only right align form labels here when the columns stop stacking
Bass Jobsen's avatar
Bass Jobsen committed
449
@media (min-width: @screen-tablet) {
450
  .form-horizontal .control-label {
Mark Otto's avatar
Mark Otto committed
451
    text-align: right;
Mark Otto's avatar
Mark Otto committed
452
  }
Mark Otto's avatar
Mark Otto committed
453
}