|
1 // |
|
2 // Forms |
|
3 // -------------------------------------------------- |
|
4 |
|
5 |
|
6 // Normalize non-controls |
|
7 // |
|
8 // Restyle and baseline non-control form elements. |
|
9 |
|
10 fieldset { |
|
11 padding: 0; |
|
12 margin: 0; |
|
13 border: 0; |
|
14 // Chrome and Firefox set a `min-width: min-content;` on fieldsets, |
|
15 // so we reset that to ensure it behaves more like a standard block element. |
|
16 // See https://github.com/twbs/bootstrap/issues/12359. |
|
17 min-width: 0; |
|
18 } |
|
19 |
|
20 legend { |
|
21 display: block; |
|
22 width: 100%; |
|
23 padding: 0; |
|
24 margin-bottom: @line-height-computed; |
|
25 font-size: (@font-size-base * 1.5); |
|
26 line-height: inherit; |
|
27 color: @legend-color; |
|
28 border: 0; |
|
29 border-bottom: 1px solid @legend-border-color; |
|
30 } |
|
31 |
|
32 label { |
|
33 display: inline-block; |
|
34 max-width: 100%; // Force IE8 to wrap long content (see https://github.com/twbs/bootstrap/issues/13141) |
|
35 margin-bottom: 5px; |
|
36 font-weight: bold; |
|
37 } |
|
38 |
|
39 |
|
40 // Normalize form controls |
|
41 // |
|
42 // While most of our form styles require extra classes, some basic normalization |
|
43 // is required to ensure optimum display with or without those classes to better |
|
44 // address browser inconsistencies. |
|
45 |
|
46 // Override content-box in Normalize (* isn't specific enough) |
|
47 input[type="search"] { |
|
48 .box-sizing(border-box); |
|
49 } |
|
50 |
|
51 // Position radios and checkboxes better |
|
52 input[type="radio"], |
|
53 input[type="checkbox"] { |
|
54 margin: 4px 0 0; |
|
55 margin-top: 1px \9; // IE8-9 |
|
56 line-height: normal; |
|
57 } |
|
58 |
|
59 // Set the height of file controls to match text inputs |
|
60 input[type="file"] { |
|
61 display: block; |
|
62 } |
|
63 |
|
64 // Make range inputs behave like textual form controls |
|
65 input[type="range"] { |
|
66 display: block; |
|
67 width: 100%; |
|
68 } |
|
69 |
|
70 // Make multiple select elements height not fixed |
|
71 select[multiple], |
|
72 select[size] { |
|
73 height: auto; |
|
74 } |
|
75 |
|
76 // Focus for file, radio, and checkbox |
|
77 input[type="file"]:focus, |
|
78 input[type="radio"]:focus, |
|
79 input[type="checkbox"]:focus { |
|
80 .tab-focus(); |
|
81 } |
|
82 |
|
83 // Adjust output element |
|
84 output { |
|
85 display: block; |
|
86 padding-top: (@padding-base-vertical + 1); |
|
87 font-size: @font-size-base; |
|
88 line-height: @line-height-base; |
|
89 color: @input-color; |
|
90 } |
|
91 |
|
92 |
|
93 // Common form controls |
|
94 // |
|
95 // Shared size and type resets for form controls. Apply `.form-control` to any |
|
96 // of the following form controls: |
|
97 // |
|
98 // select |
|
99 // textarea |
|
100 // input[type="text"] |
|
101 // input[type="password"] |
|
102 // input[type="datetime"] |
|
103 // input[type="datetime-local"] |
|
104 // input[type="date"] |
|
105 // input[type="month"] |
|
106 // input[type="time"] |
|
107 // input[type="week"] |
|
108 // input[type="number"] |
|
109 // input[type="email"] |
|
110 // input[type="url"] |
|
111 // input[type="search"] |
|
112 // input[type="tel"] |
|
113 // input[type="color"] |
|
114 |
|
115 .form-control { |
|
116 display: block; |
|
117 width: 100%; |
|
118 height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border) |
|
119 padding: @padding-base-vertical @padding-base-horizontal; |
|
120 font-size: @font-size-base; |
|
121 line-height: @line-height-base; |
|
122 color: @input-color; |
|
123 background-color: @input-bg; |
|
124 background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214 |
|
125 border: 1px solid @input-border; |
|
126 border-radius: @input-border-radius; |
|
127 .box-shadow(inset 0 1px 1px rgba(0,0,0,.075)); |
|
128 .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s"); |
|
129 |
|
130 // Customize the `:focus` state to imitate native WebKit styles. |
|
131 .form-control-focus(); |
|
132 |
|
133 // Placeholder |
|
134 .placeholder(); |
|
135 |
|
136 // Disabled and read-only inputs |
|
137 // |
|
138 // HTML5 says that controls under a fieldset > legend:first-child won't be |
|
139 // disabled if the fieldset is disabled. Due to implementation difficulty, we |
|
140 // don't honor that edge case; we style them as disabled anyway. |
|
141 &[disabled], |
|
142 &[readonly], |
|
143 fieldset[disabled] & { |
|
144 cursor: @cursor-disabled; |
|
145 background-color: @input-bg-disabled; |
|
146 opacity: 1; // iOS fix for unreadable disabled content |
|
147 } |
|
148 |
|
149 // Reset height for `textarea`s |
|
150 textarea& { |
|
151 height: auto; |
|
152 } |
|
153 } |
|
154 |
|
155 |
|
156 // Search inputs in iOS |
|
157 // |
|
158 // This overrides the extra rounded corners on search inputs in iOS so that our |
|
159 // `.form-control` class can properly style them. Note that this cannot simply |
|
160 // be added to `.form-control` as it's not specific enough. For details, see |
|
161 // https://github.com/twbs/bootstrap/issues/11586. |
|
162 |
|
163 input[type="search"] { |
|
164 -webkit-appearance: none; |
|
165 } |
|
166 |
|
167 |
|
168 // Special styles for iOS temporal inputs |
|
169 // |
|
170 // In Mobile Safari, setting `display: block` on temporal inputs causes the |
|
171 // text within the input to become vertically misaligned. As a workaround, we |
|
172 // set a pixel line-height that matches the given height of the input, but only |
|
173 // for Safari. |
|
174 |
|
175 @media screen and (-webkit-min-device-pixel-ratio: 0) { |
|
176 input[type="date"], |
|
177 input[type="time"], |
|
178 input[type="datetime-local"], |
|
179 input[type="month"] { |
|
180 line-height: @input-height-base; |
|
181 } |
|
182 input[type="date"].input-sm, |
|
183 input[type="time"].input-sm, |
|
184 input[type="datetime-local"].input-sm, |
|
185 input[type="month"].input-sm { |
|
186 line-height: @input-height-small; |
|
187 } |
|
188 input[type="date"].input-lg, |
|
189 input[type="time"].input-lg, |
|
190 input[type="datetime-local"].input-lg, |
|
191 input[type="month"].input-lg { |
|
192 line-height: @input-height-large; |
|
193 } |
|
194 } |
|
195 |
|
196 |
|
197 // Form groups |
|
198 // |
|
199 // Designed to help with the organization and spacing of vertical forms. For |
|
200 // horizontal forms, use the predefined grid classes. |
|
201 |
|
202 .form-group { |
|
203 margin-bottom: 15px; |
|
204 } |
|
205 |
|
206 |
|
207 // Checkboxes and radios |
|
208 // |
|
209 // Indent the labels to position radios/checkboxes as hanging controls. |
|
210 |
|
211 .radio, |
|
212 .checkbox { |
|
213 position: relative; |
|
214 display: block; |
|
215 margin-top: 10px; |
|
216 margin-bottom: 10px; |
|
217 |
|
218 label { |
|
219 min-height: @line-height-computed; // Ensure the input doesn't jump when there is no text |
|
220 padding-left: 20px; |
|
221 margin-bottom: 0; |
|
222 font-weight: normal; |
|
223 cursor: pointer; |
|
224 } |
|
225 } |
|
226 .radio input[type="radio"], |
|
227 .radio-inline input[type="radio"], |
|
228 .checkbox input[type="checkbox"], |
|
229 .checkbox-inline input[type="checkbox"] { |
|
230 position: absolute; |
|
231 margin-left: -20px; |
|
232 margin-top: 4px \9; |
|
233 } |
|
234 |
|
235 .radio + .radio, |
|
236 .checkbox + .checkbox { |
|
237 margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing |
|
238 } |
|
239 |
|
240 // Radios and checkboxes on same line |
|
241 .radio-inline, |
|
242 .checkbox-inline { |
|
243 display: inline-block; |
|
244 padding-left: 20px; |
|
245 margin-bottom: 0; |
|
246 vertical-align: middle; |
|
247 font-weight: normal; |
|
248 cursor: pointer; |
|
249 } |
|
250 .radio-inline + .radio-inline, |
|
251 .checkbox-inline + .checkbox-inline { |
|
252 margin-top: 0; |
|
253 margin-left: 10px; // space out consecutive inline controls |
|
254 } |
|
255 |
|
256 // Apply same disabled cursor tweak as for inputs |
|
257 // Some special care is needed because <label>s don't inherit their parent's `cursor`. |
|
258 // |
|
259 // Note: Neither radios nor checkboxes can be readonly. |
|
260 input[type="radio"], |
|
261 input[type="checkbox"] { |
|
262 &[disabled], |
|
263 &.disabled, |
|
264 fieldset[disabled] & { |
|
265 cursor: @cursor-disabled; |
|
266 } |
|
267 } |
|
268 // These classes are used directly on <label>s |
|
269 .radio-inline, |
|
270 .checkbox-inline { |
|
271 &.disabled, |
|
272 fieldset[disabled] & { |
|
273 cursor: @cursor-disabled; |
|
274 } |
|
275 } |
|
276 // These classes are used on elements with <label> descendants |
|
277 .radio, |
|
278 .checkbox { |
|
279 &.disabled, |
|
280 fieldset[disabled] & { |
|
281 label { |
|
282 cursor: @cursor-disabled; |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 |
|
288 // Static form control text |
|
289 // |
|
290 // Apply class to a `p` element to make any string of text align with labels in |
|
291 // a horizontal form layout. |
|
292 |
|
293 .form-control-static { |
|
294 // Size it appropriately next to real form controls |
|
295 padding-top: (@padding-base-vertical + 1); |
|
296 padding-bottom: (@padding-base-vertical + 1); |
|
297 // Remove default margin from `p` |
|
298 margin-bottom: 0; |
|
299 |
|
300 &.input-lg, |
|
301 &.input-sm { |
|
302 padding-left: 0; |
|
303 padding-right: 0; |
|
304 } |
|
305 } |
|
306 |
|
307 |
|
308 // Form control sizing |
|
309 // |
|
310 // Build on `.form-control` with modifier classes to decrease or increase the |
|
311 // height and font-size of form controls. |
|
312 |
|
313 .input-sm, |
|
314 .form-group-sm .form-control { |
|
315 .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @input-border-radius-small); |
|
316 } |
|
317 |
|
318 .input-lg, |
|
319 .form-group-lg .form-control { |
|
320 .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @input-border-radius-large); |
|
321 } |
|
322 |
|
323 |
|
324 // Form control feedback states |
|
325 // |
|
326 // Apply contextual and semantic states to individual form controls. |
|
327 |
|
328 .has-feedback { |
|
329 // Enable absolute positioning |
|
330 position: relative; |
|
331 |
|
332 // Ensure icons don't overlap text |
|
333 .form-control { |
|
334 padding-right: (@input-height-base * 1.25); |
|
335 } |
|
336 } |
|
337 // Feedback icon (requires .glyphicon classes) |
|
338 .form-control-feedback { |
|
339 position: absolute; |
|
340 top: 0; |
|
341 right: 0; |
|
342 z-index: 2; // Ensure icon is above input groups |
|
343 display: block; |
|
344 width: @input-height-base; |
|
345 height: @input-height-base; |
|
346 line-height: @input-height-base; |
|
347 text-align: center; |
|
348 pointer-events: none; |
|
349 } |
|
350 .input-lg + .form-control-feedback { |
|
351 width: @input-height-large; |
|
352 height: @input-height-large; |
|
353 line-height: @input-height-large; |
|
354 } |
|
355 .input-sm + .form-control-feedback { |
|
356 width: @input-height-small; |
|
357 height: @input-height-small; |
|
358 line-height: @input-height-small; |
|
359 } |
|
360 |
|
361 // Feedback states |
|
362 .has-success { |
|
363 .form-control-validation(@state-success-text; @state-success-text; @state-success-bg); |
|
364 } |
|
365 .has-warning { |
|
366 .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg); |
|
367 } |
|
368 .has-error { |
|
369 .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg); |
|
370 } |
|
371 |
|
372 // Reposition feedback icon if input has visible label above |
|
373 .has-feedback label { |
|
374 |
|
375 & ~ .form-control-feedback { |
|
376 top: (@line-height-computed + 5); // Height of the `label` and its margin |
|
377 } |
|
378 &.sr-only ~ .form-control-feedback { |
|
379 top: 0; |
|
380 } |
|
381 } |
|
382 |
|
383 |
|
384 // Help text |
|
385 // |
|
386 // Apply to any element you wish to create light text for placement immediately |
|
387 // below a form control. Use for general help, formatting, or instructional text. |
|
388 |
|
389 .help-block { |
|
390 display: block; // account for any element using help-block |
|
391 margin-top: 5px; |
|
392 margin-bottom: 10px; |
|
393 color: lighten(@text-color, 25%); // lighten the text some for contrast |
|
394 } |
|
395 |
|
396 |
|
397 // Inline forms |
|
398 // |
|
399 // Make forms appear inline(-block) by adding the `.form-inline` class. Inline |
|
400 // forms begin stacked on extra small (mobile) devices and then go inline when |
|
401 // viewports reach <768px. |
|
402 // |
|
403 // Requires wrapping inputs and labels with `.form-group` for proper display of |
|
404 // default HTML form controls and our custom form controls (e.g., input groups). |
|
405 // |
|
406 // Heads up! This is mixin-ed into `.navbar-form` in navbars.less. |
|
407 |
|
408 .form-inline { |
|
409 |
|
410 // Kick in the inline |
|
411 @media (min-width: @screen-sm-min) { |
|
412 // Inline-block all the things for "inline" |
|
413 .form-group { |
|
414 display: inline-block; |
|
415 margin-bottom: 0; |
|
416 vertical-align: middle; |
|
417 } |
|
418 |
|
419 // In navbar-form, allow folks to *not* use `.form-group` |
|
420 .form-control { |
|
421 display: inline-block; |
|
422 width: auto; // Prevent labels from stacking above inputs in `.form-group` |
|
423 vertical-align: middle; |
|
424 } |
|
425 |
|
426 // Make static controls behave like regular ones |
|
427 .form-control-static { |
|
428 display: inline-block; |
|
429 } |
|
430 |
|
431 .input-group { |
|
432 display: inline-table; |
|
433 vertical-align: middle; |
|
434 |
|
435 .input-group-addon, |
|
436 .input-group-btn, |
|
437 .form-control { |
|
438 width: auto; |
|
439 } |
|
440 } |
|
441 |
|
442 // Input groups need that 100% width though |
|
443 .input-group > .form-control { |
|
444 width: 100%; |
|
445 } |
|
446 |
|
447 .control-label { |
|
448 margin-bottom: 0; |
|
449 vertical-align: middle; |
|
450 } |
|
451 |
|
452 // Remove default margin on radios/checkboxes that were used for stacking, and |
|
453 // then undo the floating of radios and checkboxes to match (which also avoids |
|
454 // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969). |
|
455 .radio, |
|
456 .checkbox { |
|
457 display: inline-block; |
|
458 margin-top: 0; |
|
459 margin-bottom: 0; |
|
460 vertical-align: middle; |
|
461 |
|
462 label { |
|
463 padding-left: 0; |
|
464 } |
|
465 } |
|
466 .radio input[type="radio"], |
|
467 .checkbox input[type="checkbox"] { |
|
468 position: relative; |
|
469 margin-left: 0; |
|
470 } |
|
471 |
|
472 // Re-override the feedback icon. |
|
473 .has-feedback .form-control-feedback { |
|
474 top: 0; |
|
475 } |
|
476 } |
|
477 } |
|
478 |
|
479 |
|
480 // Horizontal forms |
|
481 // |
|
482 // Horizontal forms are built on grid classes and allow you to create forms with |
|
483 // labels on the left and inputs on the right. |
|
484 |
|
485 .form-horizontal { |
|
486 |
|
487 // Consistent vertical alignment of radios and checkboxes |
|
488 // |
|
489 // Labels also get some reset styles, but that is scoped to a media query below. |
|
490 .radio, |
|
491 .checkbox, |
|
492 .radio-inline, |
|
493 .checkbox-inline { |
|
494 margin-top: 0; |
|
495 margin-bottom: 0; |
|
496 padding-top: (@padding-base-vertical + 1); // Default padding plus a border |
|
497 } |
|
498 // Account for padding we're adding to ensure the alignment and of help text |
|
499 // and other content below items |
|
500 .radio, |
|
501 .checkbox { |
|
502 min-height: (@line-height-computed + (@padding-base-vertical + 1)); |
|
503 } |
|
504 |
|
505 // Make form groups behave like rows |
|
506 .form-group { |
|
507 .make-row(); |
|
508 } |
|
509 |
|
510 // Reset spacing and right align labels, but scope to media queries so that |
|
511 // labels on narrow viewports stack the same as a default form example. |
|
512 @media (min-width: @screen-sm-min) { |
|
513 .control-label { |
|
514 text-align: right; |
|
515 margin-bottom: 0; |
|
516 padding-top: (@padding-base-vertical + 1); // Default padding plus a border |
|
517 } |
|
518 } |
|
519 |
|
520 // Validation states |
|
521 // |
|
522 // Reposition the icon because it's now within a grid column and columns have |
|
523 // `position: relative;` on them. Also accounts for the grid gutter padding. |
|
524 .has-feedback .form-control-feedback { |
|
525 right: (@grid-gutter-width / 2); |
|
526 } |
|
527 |
|
528 // Form group sizes |
|
529 // |
|
530 // Quick utility class for applying `.input-lg` and `.input-sm` styles to the |
|
531 // inputs and labels within a `.form-group`. |
|
532 .form-group-lg { |
|
533 @media (min-width: @screen-sm-min) { |
|
534 .control-label { |
|
535 padding-top: ((@padding-large-vertical * @line-height-large) + 1); |
|
536 } |
|
537 } |
|
538 } |
|
539 .form-group-sm { |
|
540 @media (min-width: @screen-sm-min) { |
|
541 .control-label { |
|
542 padding-top: (@padding-small-vertical + 1); |
|
543 } |
|
544 } |
|
545 } |
|
546 } |