Is Firefox the only browser that supports floating point numbers as width declaration? (e.g. 163.4px) [duplicate]

懵懂的女人 提交于 2020-01-06 07:55:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!