Bug 54613 - percentage based margin-top for an absolute positioned element is incorrectly computed based on the height of the viewport.
Summary: percentage based margin-top for an absolute positioned element is incorrectly...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-16 20:56 PST by Philippe Wittenbergh
Modified: 2012-12-14 17:07 PST (History)
3 users (show)

See Also:


Attachments
test case (478 bytes, text/html)
2011-02-16 20:56 PST, Philippe Wittenbergh
no flags Details
test case 2 (541 bytes, text/html)
2011-02-16 21:29 PST, Philippe Wittenbergh
no flags Details
test case 3 (609 bytes, text/html)
2012-04-30 17:46 PDT, Alexandre
no flags Details
This clearly shows percentage as being calculated as 50% of height of parent, not width of parent. (309 bytes, text/html)
2012-08-03 07:30 PDT, Mark Rabjohn
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Wittenbergh 2011-02-16 20:56:51 PST
Created attachment 82750 [details]
test case

An absolute positioned element whose containing block is the viewport (initial containing block) has percentages for its margin-top computed based on the height of the viewport (instead of the width).

Css 2.1:8.3 is formal in specifying that percentages for margin (and padding) are computed based on the *width* of the containing block.
http://www.w3.org/TR/CSS21/box.html#propdef-margin

In the testcase, the div has a 5% margin-top. Widening or narrowing the window horizontally doesn’t change the position of the block.

Gecko and Opera behave correctly.
Comment 1 Philippe Wittenbergh 2011-02-16 21:29:18 PST
Created attachment 82755 [details]
test case 2

There should be no red in this test case (resize window vertically…)
Comment 2 Patrick R. Gansterer 2011-02-19 08:52:09 PST
Reproduced with r79118.
Comment 3 Mattijs 2011-12-23 06:35:47 PST
I can confirm that this bug is still there. Tested on Safari 5.1.1 (6534.51.22) and Chrome 16.0.912.63
Comment 4 Alexandre 2012-04-30 17:46:11 PDT
Created attachment 139552 [details]
test case 3
Comment 5 Alexandre 2012-04-30 17:50:12 PDT
Comment on attachment 139552 [details]
test case 3

Tested on  30 April 2012 webkit night build on Mac OSX.
Comment 6 Mark Rabjohn 2012-08-03 07:30:35 PDT
Created attachment 156378 [details]
This clearly shows percentage as being calculated as 50% of height of parent, not width of parent.

This shows margin-top configured relative to parent element. On compliant browser, the green box is outside the red box. On Chrome and Safari, the green box is fully inside of the red box.

This clearly shows percentage as being calculated as 50% of height of parent, not width of parent.
Comment 7 Bear Travis 2012-12-14 10:43:11 PST
I believe this has been fixed with bug 103246 and can be closed.
Comment 8 Philippe Wittenbergh 2012-12-14 17:07:18 PST
Yes this does work correctly now. Thanks!

Tested with WebKit nightly @r137751, the attached test cases and my real world usage work as expected.