问题
Possible Duplicate:
Are the decimal places in a CSS width respected?
I have a navigation (li
) which needs a pixel value to fit within an ul
(has display:block
).
So I use width:163.4px
for the li
's. This does work fine in Firefox (v13.0.1) but in Safari, Chrome and Opera the width is too short. (The width is there like 163px... So I guess those browsers rounding down the value.)
Explain me why only Firefox does support floating point numbers for this case?
回答1:
All browsers round fractional pixel widths, including Firefox: http://jsfiddle.net/fgD7H/1/
You can see in the fiddle that the visible width of the red div
increases only once per second, even though the actual width is incremented by 0.1 pixel ten times per second. This happens both in Chrome and in Firefox (haven't tested others).
My guess is there is some difference in rounding strategy between the two browsers (e.g. Chrome might be rounding down while Firefox might be rounding up). If you can provide a demo in jsfiddle, perhaps your problem might be more apparent. In all cases, the actual width rendered will be an integer number of pixels, so you should be able to fix the problem by setting your width to either 163px
or 164px
.
来源:https://stackoverflow.com/questions/11324792/is-firefox-the-only-browser-that-supports-floating-point-numbers-as-width-declar