> However Firefox is not perfect. Change that 3em top margin on the
> cleared <p> to 1000px and you should see some margin, but not in
> Firefox (or Opera or Konqueror surprisingly, making me wonder if I have
> interpreted the specification wrong. But it seems quite clear).
>> You've only got one inner <div> so I don't really understand the
>> question.
[quoted text clipped - 3 lines]
> Probably it may also a number of divs, not floated and appearing
> vertically in normal sequence.
Margins never collapse on floats, which may be something to bear in
mind.
> What I want to achieve here (ideally) is simple bulletproof CSS that
> can be used with simple HTML to produce the necessary. I'd like to
> avoid any need to mark the inner content as class="first-element" or
> similar.
I see.
> If _all_ margins (H&V) collapsed, in this context then I'd get the
> behaviour I need automatically, for almost no effort. 8-(
How about a table with border-spacing?
> As it is, it looks like I need to (for browser compatibility) always
> set the top margin to 0, then work from that point. The requirements
[quoted text clipped - 3 lines]
> even if I'm not sure quite which rule(s) are triggering this. Is it
> because its parent is padded?
Yes. See the definition of "adjoining" in CSS 2.1 8.3:
An element's own margins are adjoining if the 'min-height' property
is zero, and it has neither vertical borders nor vertical 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) are
adjoining.
In other words: if a box has padding then its first child goes inside
it, underneath the padding. The child's top margin therefore starts at
the bottom of the parent's top padding. The box's own margin is _above_
the padding. The margins are separated by the padding, are not
adjoining, and so don't collapse.
> Or because it's floated?
That too.
> Not what I _want_ here anyway, in this particular case, but so it
> goes.
[quoted text clipped - 5 lines]
> elements apart when I'm looking at multiple siblings (unlike the
> single element example).
Yes I see what you mean. Why not just have a series of blocks, one under
the other, and give each one a top margin of 50px and a bottom margin of
50px. Then you'll get the effect of border-spacing with 50px at the very
top and the very bottom and a 50px gap between each block.
Of course these blocks can't be floated (or their margins won't
collapse, which you want). But they can be nested inside floats. So one
float for each column, with normal-flow blocks inside it to do the rows.
To do spacing between columns you'll need 50px left margin on the first
column, 50px right margin on the last one, and 25px for all the other
left and right margins in between.
Don't set padding on anything. The fact that the containers are floats
will prevent their margins collapsing with the boxes inside them.
>> However Firefox is not perfect. Change that 3em top margin on the
>> cleared <p> to 1000px and you should see some margin, but not in
[quoted text clipped - 7 lines]
> same (i.e. it's not calculating anything inbetween), but it bases
> things on the outside of the box, not the outside of the border.
That sounds like it's also wrong, but in a different way.
> I haven't studied the spec carefully enough to judge which is better.
You should apply the box's top margin, collapsing it against any margins
it adjoins, and then add any extra offset you need to bring the box's
top border edge clear of any floats.
Firefox's behaviour only breaks in relatively unusual cases-- where the
collapsed top margin of the cleared block exceeds the clearance amount.