Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do different browsers render decimal percentage sizes differently?

Tags:

html

css

When setting widths of elements with CSS, I often end up wanting to set percentage widths that aren't whole percentages.

Do all (which I doubt) browsers handle decimal percentages in the same way, or do they render differently?

Can I accurately use it for layouts?

like image 828
Joakim Johansson Avatar asked Jan 15 '23 17:01

Joakim Johansson


2 Answers

Webkit browsers handle sub-pixel rounding very differently than other browsers. So much so that it's considered an ongoing issue. Meanwhile, Firefox and Opera seem to be able to handle sub-pixel rendering just fine; I haven't heard of many issues.

IE is another story entirely.

Here are some links for more about this topic:

  • Sub-Pixel Problems in CSS
  • Percentage Bugs in Webkit

I asked a question similar to this a little while back. This is what I've been able to gather since then (from both the accepted answer and elsewhere).

like image 117
Vin Burgh Avatar answered Jan 25 '23 22:01

Vin Burgh


Yes they do.

From my memory:

In Opera, you cannot set the decimal places of the percentage so, if you set 33.3% it uses only 33% (rather annoying) (edit:Opera may have improved on that in current version as it seems)

In Firefox, if you have percentages that add up to 100%, the pixels don't always add up to the 100% of the pixels
e.g. you have a outer div with three columns all with width: 33.33333%. If the outer div has width 100px, the columns will have 33 pixels and the sum is 99 pixels and not 100. (edit: Firefox does better than I remember. Maybe they improved)

Old IE, I cannot remember IE9 seems to work fine. The bad one of course is IE7, which rounds up (as the IE6, but who cares?). IE8/9 seem to work ok

Chrome works fine

Safari: can't remember


edit

Her one can test for oneself
http://jsfiddle.net/fTpFw/


conclusion

After I played with my fiddle in different browsers I think they all have improved. The only bad implementations (from what I want to achieve) in modern browsers is Opera and Safari. IE7 is a stopper, too. If you don't have to deal with these buggers, you could go ahead and use the percentage widths.

like image 24
yunzen Avatar answered Jan 26 '23 00:01

yunzen