width-percentage-002

Calculating widths for absolutely positioned elements

WeasyPrint

This browser

Assertion
Absolutely positioned elements whose containing block is based on a block-level element, the percentage is calculated with respect to the width of the padding box of that element.

Source

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 2 <html>
 3     <head>
 4         <title>CSS Test: Calculating widths for absolutely positioned elements</title>
 5         <link rel="author" title="Microsoft" href="http://www.microsoft.com/">
 6         <link rel="help" href="http://www.w3.org/TR/CSS21/visudet.html#the-width-property">
 7         <meta name="flags" content="">
 8         <meta name="assert" content="Absolutely positioned elements whose containing block is based on a block-level element, the percentage is calculated with respect to the width of the padding box of that element.">
 9         <style type="text/css">
10             #div1
11             {
12                 background: orange;
13                 width: 1in;
14             }
15             #div2
16             {
17                 position: relative;
18             }
19             #div3
20             {
21                 padding: 0 0.5in;
22                 width: 1in;
23             }
24             #div4
25             {
26                 width: 50%;
27                 background: blue;
28             }
29             #div1, #div3, #div4
30             {
31                 height: 1in;
32             }
33             #div3, #div4
34             {
35                 left: 0;
36                 position: absolute;
37                 top: 0;
38             }
39         </style>
40     </head>
41     <body>
42         <p>Test passes if the orange and blue boxes are the same width.</p>
43         <div id="div1"></div>
44         <div id="div2">
45             <div id="div3">
46                 <div id="div4"></div>
47             </div>
48         </div>
49     </body>
50 </html>