W3C home > Mailing lists > Public > www-style@w3.org > April 2009

Re: Control over collapsing margins

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Wed, 29 Apr 2009 09:45:06 -0700
Message-ID: <49F88412.5070604@mit.edu>
To: Patrick Garies <pgaries@fastmail.us>
CC: Aryeh Gregor <Simetrical+w3c@gmail.com>, www-style@w3.org
Patrick Garies wrote:
> The number that I tested with (just prior to that email) was 0.0001px 
> which had the described result. However, upon further testing, it seems 
> that Mozilla Firefox will suppress margin collapsing if the margin is, 
> at least, 0.00834px in width even if it isn't drawn.

What you're seeing here (presumably with all browsers) is various 
artifacts of their internal data storage for CSS data.

In particular, Gecko stores lengths internally as integers in units of 
1/60 of a CSS px.  0.5/60 = 0.008333333333333333... (the 3 repeats), so 
any value of the form 0.0083...34 will end up rounding to "1" in these 
internal units and give a nonzero length.   Any positive value smaller 
than the above repeating decimal will round to 0.

If it ends up 1, then it will in fact affect layout: everything below 
will be shifted by 1/60 of a px.  If you have 60 of these in a row, you 
will in fact see a 1px offset on screen.  There's some rounding and 
pixel-snapping that happens at paint time, of course, but that's done to 
device pixels, not CSS pixels (so if you're on a 6000 dpi device or so 
you'll actually get an entire device pixel devoted to that 1/60px of 
padding).

> I think that the Firefox implementation is bizarre and the WIE 
> implementation slightly less so; if there's going to be a threshold, it 
> should be anything greater than zero rather than some arbitrarily small 
> number.

I doubt that will happen in the near future for performance reasons. 
Gecko has been thinking for a while about switching to floating point 
for the value storage, which will replace the arbitrary threshold 0.5/60 
with the arbitrary threshold of "smallest floating-point number that can 
be expressed on your architecture"; in practice that's pretty close to 
what you're asking for, I suspect.  You'd certainly have to try pretty 
hard to tell the difference.

> Opera and Safari make more sense 

Out of curiousity, is the Opera and Safari behavior that the padding 
ends up nonzero if it's at least 0.5 CSS px, or if it's at least 0.5 
device px?  Or do they not differentiate between the two?

-Boris
Received on Wednesday, 29 April 2009 16:59:48 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 22 May 2012 03:46:58 GMT