Closed Bug 87277 Opened 20 years ago Closed 9 years ago

Tables don't collapse outer vertical margins [MARGIN-C]


(Core :: Layout: Tables, defect, P3)






(Reporter: ian, Assigned: ehsan)


(Depends on 1 open bug, Blocks 2 open bugs, )


(Keywords: css2, dev-doc-complete, testcase, Whiteboard: [Hixie-P2] Forward-compatible workaround in comments 19 and 21)


(1 file, 1 obsolete file)

Tables don't collapse vertical margins. It works fine if you take the test and
replace "table" with "block" in the style block.
(The block case is at
Whiteboard: [Hixie-P3]
Priority: -- → P2
Target Milestone: --- → mozilla1.0
The problem is in
the block top child is a tableouterframe, which does not carry the margin. In
order to get this for tables right: it should be checked first whether there is
caption frame, and use its top margin otherwise use the innertableframe margin
(// XXX except if the caption is not at the top of the table)
Target Milestone: mozilla1.0 → Future
Whiteboard: [Hixie-P3] → [Hixie-P2]
*** Bug 109517 has been marked as a duplicate of this bug. ***
*** Bug 133688 has been marked as a duplicate of this bug. ***
Reconfirmed using FizzillaCFM/2002071208. Setting All/All.
OS: Windows 2000 → All
Hardware: PC → All
*** Bug 258241 has been marked as a duplicate of this bug. ***
Sorry for the spam, but isn't it time to have a look on this?
It validates CSS and breaks compliance with IE and other browsers.
Attached file simple HTML testcase (obsolete) —
Simplified HTML test without display:table to see what IE does.
Sorry, this one is it...
Attachment #200827 - Attachment is obsolete: true
*** Bug 327277 has been marked as a duplicate of this bug. ***
I would like to underline comment #8.
I verified the bug for Firefox on Windows 98.
Another testcase:

Expected results: there should be a gap of exactly 100px between each table

Actual results: there is a 150px gap between each table.

Opera 9.0 and IE 7 beta 2 get the expected results.

I'm voting for this bug!
Can't there be some action on this simple issue? Clearly, wrapping a table in a div works around this problem, surely hardcoding this into Mozilla is an easy task?
agreed. Looking at the original report date and seeing it was from TWO THOUSAND AND ONE .. SIX [admirable restraint] YEARS AGO...

this needs to be resolved. 
Assignee: dbaron → nobody
QA Contact: amar → layout.tables
Doesn't display table establish a new formatting context, like a float or absolute positioned element?  Thus, the vertical should _not_ collapse, query?

Is this really a bug, or an aggravatingly correct rendering?

You're right about display: table establishing a new formatting context, but in CSS 2.1, neither §8.3.1 (Collapsing margins) or §9.4.1 (Block formatting contexts), mention anything about margins not collapsing, other than to say that they never do for floats.

So unless I messed something, I still think it is a bug.
You are, of course, quite right.  Thanks for reminding me to RTFM before mouthing off. :)

So floats, absolutes, and inline-blocks do not collapse even with their in flow children. While elements in block formatting contexts due to having overflow set to other than visible do not collapse with their in flow children, but do collapse externally.

It would seem that elements with display table or table-cell ought to at least not collapse with their in flow children.  That would be at least what I perceive as a correct behavior.  But, if the rules say otherwise, then the bug should be fixed, or better, IMO, modify the specs to at least throw table and table-cell in with overflow: hidden||auto.


1- Gary and Mike: yes, this is a valid bug

2- j.j., Scott, Ornette: please visit bugzilla etiquette
We're all volunteers in a community-driven project here.
"The only person who has any obligation to fix the bugs 
you want fixed is you. Never act as if you expect someone 
to fix a bug by a particular date or release. This is merely 
obnoxious, and is likely to get the bug ignored." 
Bugzilla etiquette

3- "wrapping a table in a div works around this problem":
that would be a poor and weak workaround. Increasing the number of DOM nodes is always a bad workaround. A much better workaround is to set margin-bottom of the nth table to, say, 32px, and then the margin of the nth+1 (following, next sibling) table to 0px. That way, whether vertical adjoining margin collapsing works or not, whether this bug is eventually fixed or not, the resulting margin between consecutive tables will be 32px. No javascript trick needed, no extra markup code needed; just a pure forward-compatible, future-proof CSS workaround.
A real example:

4- "hardcoding this into Mozilla is an easy task"
Ornette, I don't think a fix is that easy. This bug is closely related to the way Mozilla implements caption into the table's margin (see attachment 98261 [details]). In any case, Ornette, you can submit a patch.
Dependent on bug 50959
Depends on: 50959
Updated testcase:

Forward-compatible workaround

max (x, y) = x + y 
only and only when x == 0 or y == 0
where x is the margin-bottom of a table and 
y is the margin-top of the following (next sibling, subsequent) table

Real live example:
Whiteboard: [Hixie-P2] → [Hixie-P2] Forward-compatible workaround in comments 19 and 21
So, in today's CSS working group meeting, the group accepted option 1 in in order to resolve issue 88 on CSS 2.1 (given that there aren't yet any implementations of this).  That would make this bug invalid.

That said, I'll wait a bit before changing the state of this bug.

We should also add reftests to test the correct behavior...
Flags: in-testsuite?
That decision doesn't affect this bug. That affects whether caption margins collapse with the table, not whether the table margins collapse with other things.
Flags: wanted1.9.2? → wanted1.9.2-
No longer blocks: 372303
Duplicate of this bug: 372303
Blocks: 625703
Ehsan has a patch for this in bug 659828.
Assignee: nobody → ehsan
Depends on: 659828
Keywords: dev-doc-needed
This was fixed by bug 659828.  I enabled the tests for this bug:
Closed: 9 years ago
Flags: in-testsuite? → in-testsuite+
Resolution: --- → FIXED
Target Milestone: Future → mozilla10
Depends on: 691591
This is just listed on Firefox 10 for developers with a link to the blog post, since it's just bringing us into line with the spec.
> Forward-compatible workaround
> =============================
> max (x, y) = x + y 
> only and only when x == 0 or y == 0
> where x is the margin-bottom of a table and 
> y is the margin-top of the following (next sibling, subsequent) table
> Real live example:

Corrected link:

line 52: table {width: 100%; margin: 0px auto 32px auto;}
You need to log in before you can comment on or make changes to this bug.