<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>15993</bug_id>
          
          <creation_ts>2012-02-15 12:22:43 +0000</creation_ts>
          <short_desc>The margin collapsing quirks is not described properly</short_desc>
          <delta_ts>2013-06-06 20:33:37 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#tables</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>adrianba</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>dbaron</cc>
    
    <cc>eoconnor</cc>
    
    <cc>ian</cc>
    
    <cc>jackalmage</cc>
    
    <cc>mike</cc>
    
    <cc>mjs</cc>
    
    <cc>sylvaing</cc>
    
    <cc>tross</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>64138</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-02-15 12:22:43 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/rendering.html
Multipage: http://www.whatwg.org/C#tables
Complete: http://www.whatwg.org/c#tables

Comment:
&quot;When a Document is in quirks mode, vertical margins on HTML elements at the
top or bottom of td or th elements are expected to be collapsed to zero.&quot; is
wrong. The top margin is correct, but the *bottom* margin should only be
collapsed for p elements.
http://mxr.mozilla.org/mozilla-central/source/layout/style/quirk.css#135

Posted from: 85.227.157.105 by simonp@opera.com
User agent: Opera/9.80 (Macintosh; Intel Mac OS X 10.7.2; U; en) Presto/2.10.229 Version/11.61</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64140</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-02-15 12:51:05 +0000</bug_when>
    <thetext>Seems like body shouldn&apos;t collapse bottom margin, and we can have a limited set of elements that collapse the top margin for body, td and th. Empty elements (same set) at the start of body, td and th should get collapsed bottom margin. Empty elements (same set) at the end of td and th should get collapsed top margin.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64141</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-02-15 12:52:08 +0000</bug_when>
    <thetext>Also, not collapse, but set to 0.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70577</commentid>
    <comment_count>3</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-07-18 16:17:37 +0000</bug_when>
    <thetext>This bug was cloned to create bug 18054 as part of operation convergence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73961</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-15 17:59:59 +0000</bug_when>
    <thetext>I don&apos;t understand what it is you want me to write here.

(In reply to comment #2)
&gt; Also, not collapse, but set to 0.

No, collapse, because the whole point is that all the elements at the top of the document have their margins go to zero. As in the &lt;h1&gt;&apos;s top margin here:

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1771

But I agree that the statement in the spec isn&apos;t accurate enough. For example, the &lt;body&gt;&apos;s top margin itself doesn&apos;t eat the others, it&apos;s just that the whole stack at the top goes to the body&apos;s 8px.

Not really sure what the right solution is here. Anyone want to have a crack at defining this quirk? (With tests, ideally.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73990</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-09-17 07:43:38 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; I don&apos;t understand what it is you want me to write here.

I want you to basically copy Gecko (but don&apos;t include multicol).

&gt; (In reply to comment #2)
&gt; &gt; Also, not collapse, but set to 0.
&gt; 
&gt; No, collapse, because the whole point is that all the elements at the top of
&gt; the document have their margins go to zero.

No, the point is to be compatible with the Web. It&apos;s hard to know what has the best Web compat properties, I guess. Opera has bugs reported in this area where I have concluded that Gecko&apos;s behavior would be better.

&gt; As in the &lt;h1&gt;&apos;s top margin here:
&gt; 
&gt;    http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1771

This doesn&apos;t collapse in Firefox.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74092</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-19 22:22:36 +0000</bug_when>
    <thetext>http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=1771 renders the same in Opera, WebKit, and IE. Why would we want to follow Gecko here, which is the lone one not collapsing the margin?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>76345</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-10-15 23:18:44 +0000</bug_when>
    <thetext>zcorpan: ping</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>76359</commentid>
    <comment_count>8</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-10-16 08:31:33 +0000</bug_when>
    <thetext>Because:

I&apos;d like to minimize the amount of quirks we have to the set that is *needed* for Web compat, and not let quirks leak to new features (e.g. &lt;section&gt;). Firefox has a fixed list of elements that have 0 margin, and this appears to be Web compatible enough that Gecko haven&apos;t felt any need to change it. (We&apos;ve similarly limited the two CSS parsing quirks to a fixed set of properties even though no browser had that (Gecko had a blacklist rather than a whitelist but has now implemented the whitelist).)

I don&apos;t really understand what other browsers do to be able to accurately describe it in a spec.

Opera&apos;s behavior breaks some sites that would be fixed if we implemented Gecko&apos;s behavior. (Comment 0 describes such an instance.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82174</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-01-26 00:00:30 +0000</bug_when>
    <thetext>So what exactly does Gecko do? I really don&apos;t understand what you want the spec to say (I can&apos;t just &quot;copy Gecko&quot; since Gecko is written in C++ and the spec is written in English prose).

Do other browser vendors have an opinion on this? For example, are there know Gecko compatibility issues here? Are other browsers (WebKit, Microsoft) willing to change to match Gecko?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82176</commentid>
    <comment_count>10</comment_count>
    <who name="L. David Baron (Mozilla)">dbaron</who>
    <bug_when>2013-01-26 00:10:58 +0000</bug_when>
    <thetext>The Gecko behavior is actually written in CSS, not C++; see the link to quirk.css in comment 0.  That said, I&apos;m not particularly happy with that behavior, though I&apos;m not sure if I&apos;m any happier with the various alternatives proposed in https://bugzilla.mozilla.org/show_bug.cgi?id=33784 or elsewhere. (I thought I had a better one in there, but I don&apos;t see it.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82177</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-01-26 00:48:17 +0000</bug_when>
    <thetext>dbaron: What does :-moz-only-whitespace:-moz-last-node do?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82182</commentid>
    <comment_count>12</comment_count>
    <who name="L. David Baron (Mozilla)">dbaron</who>
    <bug_when>2013-01-26 01:06:10 +0000</bug_when>
    <thetext>:-moz-only-whitespace matches a node all of whose children are either (a) comments, (b) processing instructions, or (c) text nodes that do not contain a character other than space, tab, LF, CR, or form feed.  (It&apos;s a superset of :empty, which considers only (a), (b), and text nodes with zero-length data.)

:-moz-last-node matches an element that does not have any later sibling other than (a), (b), or (c) as above.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82183</commentid>
    <comment_count>13</comment_count>
    <who name="L. David Baron (Mozilla)">dbaron</who>
    <bug_when>2013-01-26 01:08:29 +0000</bug_when>
    <thetext>(Note that I don&apos;t think Gecko CDATA section nodes anymore.  If it did, I think the above definitions might need adjusting for them (probably by treating them just like text nodes).)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82212</commentid>
    <comment_count>14</comment_count>
    <who name="Sylvain Galineau">sylvaing</who>
    <bug_when>2013-01-27 00:32:23 +0000</bug_when>
    <thetext>Simon, can you share an example of a site broken in Opera that you believe would be fixed by this change?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84789</commentid>
    <comment_count>15</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-03-21 19:50:24 +0000</bug_when>
    <thetext>The site that led me to report this bug was probably this one:

http://boards.4chan.org/n/

At the time (about a year ago), it was in quirks mode and expected the bottom margin of &lt;blockquote&gt; in &lt;td&gt; to *not* be collapsed, which is what happens in WebKit/Gecko but not Opera. (Apparently IE9 collapses, but the site wasn&apos;t broken in IE. Maybe they had a CSS hack for IE?) We sitepatched it, and now it appears this page isn&apos;t in quirks mode anymore.

I would be OK with going with IE or WebKit instead of Gecko, except that I don&apos;t know what they&apos;re doing. They do not match the spec.

Here are two examples (which I found in our bug database with a brief search):

This one is broken in Opera/the spec, and don&apos;t collapse in IE9/Gecko/WebKit:
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2174

This one collapses in Opera/IE9/the spec, and don&apos;t collapse in Gecko/WebKit:
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2175</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84790</commentid>
    <comment_count>16</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-03-21 20:16:25 +0000</bug_when>
    <thetext>Here are more examples that illustrate that Gecko/WebKit/Opera differ from the spec. (IE&apos;s log is empty which suggests it&apos;s close to what the spec does, however &lt;hr&gt; doesn&apos;t collapse, which probably means IE doesn&apos;t respect specified margins on &lt;hr&gt;.)

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2176

Note that this only tests &lt;td&gt;, not &lt;body&gt;. IIRC, the handling of bottom margin differ between the two.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84791</commentid>
    <comment_count>17</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-03-21 20:22:47 +0000</bug_when>
    <thetext>Moreover, the spec says to collapse the margin even if a margin was specified in author CSS, which does not match any of IE9/Opera/WebKit/Gecko:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2177</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86957</commentid>
    <comment_count>18</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 22:31:02 +0000</bug_when>
    <thetext>As far as I can tell, IE9&apos;s behaviour is simple:

  Any UA-set margin that collapses with, or is:
    - the margin adjacent to the top of a Document, &lt;td&gt;, or &lt;th&gt;
    - the last margin in a Document, &lt;td&gt;, or &lt;th&gt;, even if that margin is not
      adjacent to the bottom of the Document, &lt;td&gt;, or &lt;th&gt; in question,
  ...gets set to zero.

I couldn&apos;t reproduce the &lt;hr&gt; thing.

This, however, is apparently not Web-compatible (per comment 15)?


Gecko&apos;s behaviour is noticeably different than IE9/Safari/Chrome, so I&apos;m reluctant to adopt it, but it does have the advantage of being quite narrow. As far as I can tell, here&apos;s what that behaviour is:

  A node is purple if it is a text node that is not inter-element whitespace,
  or if it is an element node.

  A node is blank if it is an element that contains no purple nodes.

  Set S consists of the following elements: p, dl, multicol, blockquote, h1–h6, 
  listing, plaintext, xmp, pre, ul, menu, dir, ol.

  Any element from the set S that is the child of a &lt;body&gt;, &lt;td&gt;, or &lt;th&gt; 
  element and has no purple previous siblings has its top margin set to zero.

  Any element from the set S that is the child of a &lt;body&gt;, &lt;td&gt;, or &lt;th&gt; 
  element, has no purple previous siblings, and is blank, has its bottom margin 
  set to zero also.

  Any element from the set S that is the child of a &lt;td&gt; or &lt;th&gt; element, has
  no purple following siblings, and is blank, has its top margin set to zero.

  Any &lt;p&gt; element that is the child of a &lt;td&gt; or &lt;th&gt; element and has no 
  purple following siblings has its bottom margin set to zero, even if it is
  not blank.

We&apos;d drop &apos;multicol&apos; if we used this definition since the spec doesn&apos;t give it margins anyway.

Is this Web-compatible even though it doesn&apos;t match IE or Safari/Chrome?

(Let me know if I got the descriptions above wrong. In the absence of disagreement, I&apos;ll spec Gecko&apos;s behaviour using the text above more or less verbatim, as Simon originally requested over a year ago. If anyone has a better term than &quot;purple&quot;, let me know. The term &quot;blank&quot; is from Selectors. The name of set &quot;S&quot; will be more verbose.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86960</commentid>
    <comment_count>19</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 22:37:01 +0000</bug_when>
    <thetext>astearns suggests &quot;substantial&quot; instead of &quot;purple&quot;, which seems reasonable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86963</commentid>
    <comment_count>20</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-04-29 22:46:22 +0000</bug_when>
    <thetext>I believe your description is correct as long as &quot;has its * margin set to zero&quot; just means there is a UA sheet rule to that effect (so that pages can still change the styling however they want).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86964</commentid>
    <comment_count>21</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-04-29 22:49:06 +0000</bug_when>
    <thetext>Fwiw, Gecko calls the &quot;purple&quot; nodes &quot;significant children&quot;.  Though significance is parametrized on some booleans (&quot;text is significant&quot; and &quot;whitespace is significant&quot;).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86966</commentid>
    <comment_count>22</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 23:00:17 +0000</bug_when>
    <thetext>Yeah, this would be setting the margins in the UA sheet only.

Actually, Tab brings up an interesting point in IRC, which is that Gecko is affected by &apos;white-space:pre&apos;:

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2231

So I guess the definition (using &apos;significant&apos; instead of &apos;purple&apos;) has to be:

  A node is significant if it is an element or if it generates a box that is not
  an inline box containing only collapsible whitespace.

...or some such?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86967</commentid>
    <comment_count>23</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 23:07:15 +0000</bug_when>
    <thetext>Make that:

  A node is significant if it is an element or if it generates a box that is not
  an anonymous inline box containing only collapsible whitespace.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86968</commentid>
    <comment_count>24</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 23:08:16 +0000</bug_when>
    <thetext>(Note to self: when fixing this, search for &quot;collapsed to zero&quot;.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86970</commentid>
    <comment_count>25</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 23:20:47 +0000</bug_when>
    <thetext>Nevermind, I&apos;m dumb. Ignore comments 22 and 23. My test was misleading.

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2234</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86972</commentid>
    <comment_count>26</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-29 23:23:43 +0000</bug_when>
    <thetext>(And for the record, Re comment 22: the comments Tab made on IRC were correct, it was my mistake in extrapolating from them that led to the error above. :-) )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86979</commentid>
    <comment_count>27</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-04-30 01:18:39 +0000</bug_when>
    <thetext>I was about to say!  This stuff can&apos;t depend on the value of white-space, since it affects selector-matching in Gecko.  ;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88855</commentid>
    <comment_count>28</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-06-06 20:33:37 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7924.
Check-in comment: Define margin collapsing quirk in more detail.
http://html5.org/tools/web-apps-tracker?from=7923&amp;to=7924</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>