Font-Size rounding issue with CSS
I am trying to set the font-size to 0开发者_运维技巧.7272727272 but when the page gets rendered, the Computed style is showing .73333333. Is this a bug with firefox, or is there something i can do to maintain the .727272727 font size.
I don't think you can guarantee a font size to that many decimal places.
As far as I can tell there's nothing the CSS spec that specifies the precision of font sizes/lengths - just that a decimal number can be used. Judging from the question and one of the other answers the precision of font sizes will not only vary from browser to browser, but even between different builds/releases of the same browser.
You'll probably be able to count on a precision of two decimal places, but no more.
Screen monitors deal with pixels, of which there is a finite number to work with. So whether you are precise to two decimal places or ten decimal places you will still only get a pixel result when it is rendered.
Having said that, if you are trying to express a relative proportion, then something that has many decimal places will give the most precise figure to the browser, so that you know which way it will render.
If the browser is given a value like 17.5px obviously it cannot actually display 17.5px it will either round up or round down.
I haven't given a specific example, as that would require a little too much thinking, but I hope that makes sense.
In my firebug it is changing to 0.727273px and it is almost similar size.
It is up to the browser on how precise the values will be. But honestly, 0.006 pixels? I doubt it's that big of a deal.
精彩评论