margin-em-inherit-001.xht (2885B)
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: inherit applied on margin set with em</title> 8 9 <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/" /> 10 <link rel="help" title="4.3.2 Length" href="http://www.w3.org/TR/CSS21/syndata.html#length-units" /> 11 <link rel="help" title="6.2.1 The 'inherit' value" href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit" /> 12 <link rel="help" href="http://www.w3.org/TR/css-cascade-3/#inherit" /> 13 <link rel="help" href="http://www.w3.org/TR/css-cascade-4/#inherit" /> 14 <link rel="help" title="8.3 Margin properties" href="http://www.w3.org/TR/CSS21/box.html#margin-properties" /> 15 <link rel="match" href="margin-em-inherit-001-ref.xht" /> 16 17 <meta content="The 'em' unit is equal to the computed value of the 'font-size' property of the element on which it is used. When inherit keyword is used, the property takes the same computed value - a length value in this testcase - as the property for the element's parent." name="assert" /> 18 <meta content="image" name="flags" /> 19 20 <style type="text/css"><![CDATA[ 21 body {margin: 8px;} 22 23 p 24 { 25 font: 1em/1.25 serif; 26 margin: 1em 0em; 27 } 28 29 div#grand-parent {width: 600px;} 30 31 div#parent 32 { 33 background-color: green; 34 border: white solid 6px; 35 /* 36 Such border prevents margin collapsing between 37 #parent's vertical margins and #child's vertical margins 38 */ 39 font-size: 28px; 40 margin: 2em 3em 1em 4em; /* 56px 84px 28px 112px */ 41 } 42 43 div#child 44 { 45 font-size: 40px; 46 margin: inherit; 47 /* 48 What is inherited is a computed length value: so 49 it is 56px 84px 28px 112px and not 80px 120px 40px 160px 50 */ 51 } 52 53 div#abs-pos-overlapping-green 54 { 55 left: 238px; 56 position: absolute; 57 top: 174px; 58 } 59 60 /* 61 8px (body's margin-left) 62 + 112px (#parent's margin-left) 63 + 6px (#parent's border-left) 64 + 112px (#child's margin-left) 65 ================== 66 238px 67 */ 68 69 /* 70 16px (max(8px, 16px): body's margin-top collapses with p's margin-top) 71 + 20px (first line) 72 + 20px (second line) 73 + 56px (max(16px, 56px): p's margin-bottom collapses with #parent's margin-top) 74 + 6px (#parent's border-top) 75 + 56px (#child's margin-top) 76 ================== 77 174px 78 */ 79 ]]></style> 80 81 </head> 82 83 <body> 84 85 <p>Test passes if there is a filled green<br /> 86 rectangle and if there is no red.</p> 87 88 <div id="grand-parent"> 89 <div id="parent"> 90 <div id="child"><img src="support/100x100-red.png" alt="Image download support must be enabled" /></div> 91 </div> 92 </div> 93 94 <div id="abs-pos-overlapping-green"><img src="support/swatch-green.png" width="100" height="100" alt="Image download support must be enabled" /></div> 95 96 </body> 97 </html>