In the below code I have element trees with three DIVs; the outer DIV establishes a positioning context and the "middle" DIV uses absolute positioning to put its top left corner in the center of the outer DIV. This works fine in all browsers.
Then I try to do relative positioning on the inner DIV with respect to the middle DIV. I try both moving up and left with percentages, which works fine in IE, but in Firefox/Safari it only gives an effect on moving left, not up.
Anybody can give me a clue why this happens?
Best regards
Mike
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>title</title>
- <style type="text/css">
- div.outer {
- width: 200px;
- height: 100px;
- border: 1px solid black;
- position: relative;
- }
- div.middle {
- position: absolute;
- top: 50%;
- left: 50%;
- border: 1px dotted green;
- }
- div.inner {
- width: 70px;
- height: 20px;
- border: 1px solid red;
- text-align: center;
- position: relative;
- }
- #horiz div.inner {
- left: -50%;
- }
- #vert div.inner {
- top: -50%;
- }
- </style>
- </head>
- <body>
- <div id="horiz" class="outer">
- <div class="middle">
- <div class="inner">Block</div>
- </div>
- </div>
- <div id="vert" class="outer">
- <div class="middle">
- <div class="inner">Block</div>
- </div>
- </div>
- </body>
- </html>