W3C home > Mailing lists > Public > www-style@w3.org > March 2011

[CSS21] Issue 159 (margin collapsing rewrite) (Was: [CSS21] 8.3.1 margin-bottom of 'collapsed through' box with clearance applied)

From: Anton Prowse <prowse@moonhenge.net>
Date: Thu, 17 Mar 2011 18:52:41 +0100
Message-ID: <4D824A69.6070506@moonhenge.net>
To: www-style <www-style@w3.org>
CC: Arron Eicholz <Arron.Eicholz@microsoft.com>, Bruno Fassino <fassino@gmail.com>
On 11/03/2011 19:49, Arron Eicholz wrote:
> The CSSWG resolved to  the 8.3.1 text below.

> ------
> 8.3.1 Collapsing margins
>
> In CSS, the adjoining margins of two or more boxes (which might or might not be siblings) can combine to form a single margin. Margins that combine this way are said to collapse, and the resulting combined margin is called a collapsed margin.
>
> Adjoining vertical margins collapse, except:
>
>      * Margins of the root element's box do not collapse.
>      * If the top and bottom margins of an element with clearance are adjoining, its margins collapse with the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block.
>
> Horizontal margins never collapse.
>
> Two margins are adjoining if and only if:
>
>      * both belong to in-flow block-level boxes that participate in the same block formatting context
>      * no line boxes, no clearance, no padding and no border separate them (Note that certain zero-height line boxes (see 9.4.2) are ignored for this purpose.)
>      * both belong to vertically-adjacent box edges, i.e. form one of the following pairs:
>            o top margin of a box and top margin of its first in-flow child
>            o bottom margin of box and top margin of its next in-flow following sibling
>            o bottom margin of a last in-flow child and bottom margin of its parent if the parent has 'auto' computed height
>            o top and bottom margins of a box that does not establish a new block formatting context and that has zero computed 'min-height', zero or 'auto' computed 'height', and no in-flow children
>
> A collapsed margin is considered adjoining to another margin if any of its component margins is adjoining to that margin.
>
> Note. Adjoining margins can be generated by elements that are not related as siblings or ancestors.
>
> Note the above rules imply that:
>
>      * Margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).
>      * Margins of elements that establish new block formatting contexts (such as floats and elements with 'overflow' other than 'visible') do not collapse with their in-flow children.
>      * Margins of absolutely positioned boxes do not collapse (not even with their in-flow children).
>      * Margins of inline-block boxes do not collapse (not even with their in-flow children).
>      * The bottom margin of an in-flow block-level element always collapses with the top margin of its next in-flow block-level sibling, unless that sibling has clearance.
>      * The top margin of an in-flow block element collapses with its first in-flow block-level child's top margin if the element has no top border, no top padding, and the child has no clearance.
>      * The bottom margin of an in-flow block box with a 'height' of 'auto' and a 'min-height' of zero collapses with its last in-flow block-level child's bottom margin if the box has no bottom padding and no bottom border and the child's bottom margin does not collapse with a top margin that has clearance.
>      * A box's own margins collapse if the 'min-height' property is zero, and it has neither top or bottom borders nor top or bottom padding, and it has a 'height' of either 0 or 'auto', and it does not contain a line box, and all of its in-flow children's margins (if any) collapse.
>
> When two or more margins collapse, the resulting margin width is the maximum of the collapsing margins' widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the maximum of the absolute values of the adjoining margins is deducted from zero.
>
> If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it. In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed.
>
>      * If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.
>      * Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved. The position of the element's top border edge is the same as it would have been if the element had a non-zero bottom border.
>
> Note that the positions of elements that have been collapsed through have no effect on the positions of the other elements with whose margins they are being collapsed; the top border edge position is only required for laying out descendants of these elements.

A couple of trivial issues that haven't been raised before:

#1)
The sentence "(Note that certain zero-height line boxes (see 9.4.2) are 
ignored for this purpose.)" was introduced as the resolution to Issue 
204 which concerned the fact that 9.4.2 required zero-height line boxes 
to exist which were to be ignored for the purposes of margin collapsing, 
but 8.3.1 confusingly omitted to consider this case.

However, the resolution to Issue 199 which questioned the situations in 
which line boxes exist resulted in changing 9.4.2 so that those 
zero-height line boxes no longer exist.  Hence Issue 204 has been 
obsoleted and there's no longer any need for the sentence in 8.3.1. That 
sentence needs to be removed.


#2)
In the list of practical implications of the adjacency/collapsing rules, 
the last four items state that collapsing occurs between certain 
elements' margins and their other margins or their children's margins 
under certain conditions.  However, certain elements which establish 
block formatting contexts may also satisfy those stated conditions and 
yet still do not collapse their margins as described (as can be deduced 
from the adjacency/collapsing rules).  So those four items need to be 
qualified to exclude BFCs.


Cheers,
Anton Prowse
http://dev.moonhenge.net
Received on Thursday, 17 March 2011 17:53:14 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:38 GMT