contain-content-002.html (1696B)
1 <!DOCTYPE html> 2 3 <meta charset="UTF-8"> 4 5 <title>CSS Containment Test: 'contain: content' and margin collapsing</title> 6 7 <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/"> 8 <link rel="help" href="https://www.w3.org/TR/css-contain-1/#contain-property"> 9 <link rel="match" href="reference/contain-paint-ifc-011-ref.html"> 10 11 <meta content="This test checks that a block element with 'contain: content' establishes a new block formatting context which is independent and separate from others. This causes margin collapsing to be ineffective among vertically-adjacent boxes. In this test, the top margin of parent boxes and top margin of their respective first in-flow child do not collapse. Also, in this test, the bottom margin of the last in-flow child of boxes and bottom margin of their respective parent boxes do not collapse." name="assert"> 12 13 <style> 14 div 15 { 16 contain: content; 17 margin: 30px 0px; 18 } 19 20 div#grand-grand-parent-orange 21 { 22 background-color: orange; 23 } 24 25 div#grand-parent-blue 26 { 27 background-color: blue; 28 } 29 30 div#parent-lime 31 { 32 background-color: lime; 33 } 34 35 div#collapse-through-child /* margin collapsing through element */ 36 { 37 contain: none; 38 } 39 </style> 40 41 <p>Test passes if there are 5 horizontal stripes across the page in this order (from top to bottom): an orange stripe, a blue stripe, a bright green stripe, a blue stripe and then an orange stripe. 42 43 <div id="grand-grand-parent-orange"> 44 45 <div id="grand-parent-blue"> 46 47 <div id="parent-lime"> 48 49 <div id="collapse-through-child"></div> 50 51 </div> 52 53 </div> 54 55 </div>