block formatting contexts
A block formatting context is a box that satisfies at least one of the following:
- the value of “float” is not “none”,
- the used value of “overflow” is not “visible”,
- the value of “display” is “table-cell”, “table-caption”, or “inline-block”,
- the value of “position” is neither “static” nor “relative”.
In a block formatting context:
- boxes are laid out one after the other, vertically, beginning at the top of a containing block. The vertical distance between two sibling boxes is determined by the ‘margin’ properties. Vertical margins between adjacent block boxes in a block formatting context collapse.
- each box’s left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch). This is true even in the presence of floats (although a box’s line boxes may shrink due to the floats), unless the box establishes a new block formatting context (in which case the box itself may become narrower due to the floats).
Block formatting contexts contain floats and do not overlap floats.
Vertical margins do not collapse outside of block formatting contexts.
In IE 6, hasLayout establishes (more or less) block formatting contexts, hence the use of zoom
(MS proprietary property) in these pages.
You should avoid using clearfix
(see Everything you Know about Clearfix is Wrong).