Open nicoburns opened 1 month ago
Of particular note: this affects the https://wpt.live/css/cssom-view/offsetTopLeft-inline.html test
As it looks like this is going to be discussed, I thought I would add my expectations from an web author's perspective:
<body>
element to be treated speciallyoffsetTop
/offsetLeft
to be computed relative to the viewport if there are no positioned nodes intervening.offsetTop
/offsetLeft
to be computed relative to the <html>
element if <html>
is positioned and there are no other positioned nodes intervening.
Context
This issue was discovered when trying to run unrelated WPT tests (css-flexbox tests) in Servo. It turns out that many of them depend on this non-standard behaviour. For example https://wpt.live/css/css-flexbox/align-content-horiz-001b.html
Specification
The spec says:
offsetParent
offsetTop/offsetLeft
Test Case
Per the spec, the
offsetParent
for#target
ought to be the<body>
element. And therefore theoffsetTop
andoffsetLeft
both ought to be 0. However, actual browsers (tested Chrome 126.0.6478.127, Firefox 127.0.2, Safari 17.5) return 8 for both properties.The actual observed behaviour seems to be that while browsers are correctly returning the
<body>
element as theoffsetParent
, they are actually computing theoffsetLeft
/offsetTop
offsets relative to the border-edge of the<html>
element rather than the padding-edge of the<body>
element in this case.(note that this is only the case if the
<body>
isposition: static
. If the<body>
isposition: relative
then all browsers return 0 as per the spec).Implications
This issue affects a number of of WPT tests and means that browsers that conform to both the offsetTop/offsetLeft spec and the css-flexbox spec cannot pass those tests.
Either the spec or browser behaviour ought to be updated.
In
css-flexbox
, the following tests usedata-offset-x
/data-offset-y
assertions and are potentially affected (but will only be affected if these are used with anoffsetParent
that corresponds to the<body>
:Questions
position:relative
to the<body>
and updating the expected offset values to match) be likely to be accepted?