position-relative-nested-001.xht (1874B)
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: Vertical centering with negative and positive top positioning</title> 5 <link rel="author" title="Microsoft" href="http://www.microsoft.com/" /> 6 <link rel="help" href="http://www.w3.org/TR/CSS21/visuren.html#positioning-scheme" /> 7 <link rel="match" href="position-relative-nested-001-ref.xht" /> 8 9 <meta name="assert" content="Equal 50% positive and negative positioning can vertically center objects." /> 10 <style type="text/css"> 11 #outer 12 { 13 background: green repeat-x center url('support/red_box.png'); 14 /* red_box.png is a 100px by 100px red square */ 15 height: 300px; 16 width: 200px; 17 } 18 #inner 19 { 20 background-color: red; 21 height: 100px; 22 position: relative; 23 top: 50% 24 } 25 #inner-most 26 { 27 background-color: green; 28 height: 150px; 29 /* 150px == top-half of red_box.png's height + #inner's height */ 30 position: relative; 31 top: -50%; 32 /* 50% is 50% of the height of #inner-most's containing block 33 which is #inner */ 34 /* to move the top of the #inner-most box from pixel 150 35 on the y-axis of #outer to pixel 100 on the y-axis of #outer */ 36 } 37 </style> 38 </head> 39 <body> 40 <p>Test passes if there is <strong>no red</strong>.</p> 41 <div id="outer"> 42 <div id="inner"> 43 <div id="inner-most"></div> 44 </div> 45 </div> 46 </body> 47 </html>