margin-005.xht (2438B)
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>CSS Test: Margin with a value of 'auto'</title> 5 <link rel="author" title="Microsoft" href="http://www.microsoft.com/" /> 6 <link rel="reviewer" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/" /> <!-- 2012-08-13 --> 7 <link rel="help" href="http://www.w3.org/TR/CSS21/box.html#propdef-margin" /> 8 <link rel="help" href="http://www.w3.org/TR/CSS21/box.html#margin-properties" /> 9 <link rel="match" href="margin-005-ref.xht" /> 10 11 <meta name="assert" content="The 'margin' property with a value of 'auto' correctly sizes the margin. In normal flow, 'margin-top: auto' and 'margin-bottom: auto' for block-level, non-replaced elements are resolved as 0. In normal flow, 'margin-left: auto' and 'margin-right: auto' for block-level, non-replaced elements are resolved according to the constraint equation for the width of containing block: 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block" /> 12 <style type="text/css"> 13 #wrapper 14 { 15 position: relative; 16 } 17 #div1, #div2 18 { 19 border: 10px solid green; 20 } 21 #div1, #reference 22 { 23 left: 0; 24 position: absolute; 25 top: 0; 26 } 27 28 /* 29 In this test, #div1, which is absolutely positioned, is 30 #div2's containing block. In which case, the width of #div1 is 31 shrink-to-fit to the width of #div2 plus its borders. 32 http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width 33 */ 34 35 #div2 36 { 37 height: 1in; 38 margin: auto; 39 width: 3in; 40 } 41 #reference 42 { 43 border: 20px solid red; 44 height: 96px; 45 width: 288px; 46 } 47 </style> 48 </head> 49 <body> 50 <p>Test passes if there is <strong>no red</strong>.</p> 51 <div id="wrapper"> 52 <div id="reference"></div> 53 <div id="div1"> 54 <div id="div2"></div> 55 </div> 56 </div> 57 </body> 58 </html>