margin-collapse-clear-017.xht (2450B)
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 5 <head> 6 7 <title>CSS Test: Margin collapsing - margins of a 'collapsed through' box without clearance can collapse with parent block's bottom margin</title> 8 9 <link rel="help" href="http://www.w3.org/TR/CSS21/box.html#collapsing-margins" /> 10 <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/" /> 11 <link rel="author" title="Daniel Schattenkirchner" href="mailto:crazy-daniel@gmx.de" /> 12 <link rel="match" href="margin-collapse-clear-017-ref.xht" /> 13 14 <meta content="An element that does not have clearance applied to it can collapse its top margin with its parent block's bottom margin. Margins of a 'collapsed through' box without clearance applied to it can collapse with its parent block's bottom margin. An element with 'clear' set to a value other than 'none' can create a clearance only if and only when there is an earlier (in the source document) floating box." name="assert" /> 15 <meta content="image" name="flags" /> 16 17 <style type="text/css"><![CDATA[ 18 body 19 { 20 background: white url("support/ruler-v-100px-200px-300px.png") no-repeat; 21 margin: 34px 8px 8px 55px; 22 /* 23 34px : body's top margin collapsing with p's top margin: max(34px, 16px) 24 + 20px : p's 1st line box height 25 + 20px : p's 2nd line box height 26 + 16px : p's bottom margin 27 + 10px : height of topmost green bar 28 ====== 29 100px 30 */ 31 } 32 33 p 34 { 35 font-size: 16px; 36 line-height: 20px; 37 margin: 1em 8px; 38 } 39 40 div#parent-block {margin-bottom: 100px;} 41 42 div.vertical-gap-separator 43 { 44 background-color: green; 45 height: 10px; 46 } 47 48 div#element-without-clearance 49 { 50 clear: both; 51 margin-top: 100px; 52 } 53 54 /* 55 In this test, div#element-without-clearance 56 is what the spec refers to as 57 'collapsed through' box 58 http://www.w3.org/TR/CSS21/box.html#collapsed-through 59 */ 60 ]]></style> 61 62 </head> 63 64 <body> 65 66 <p>Test passes if there is a vertical gap<br /> 67 of exactly 100px between 2 green bars.</p> 68 69 <div id="parent-block"> 70 <div class="vertical-gap-separator"></div> 71 <div id="element-without-clearance"></div> 72 </div> 73 74 <div class="vertical-gap-separator"></div> 75 76 <!-- 77 div#element-without-clearance's margin-top should collapse 78 with #parent-block's margin-bottom: max(100px, 100px) = 100px 79 --> 80 81 </body> 82 </html>