WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
295322
Anchor-positioned, fixed-positioned element might get clipped by the viewport
https://bugs.webkit.org/show_bug.cgi?id=295322
Summary
Anchor-positioned, fixed-positioned element might get clipped by the viewport
Jake Archibald
Reported
2025-07-02 01:29:27 PDT
Created
attachment 475739
[details]
Chrome screenshot Observed in release 222. Reduced case:
https://codepen.io/jaffathecake/pen/ZYGNyzr?editors=1100
- click "Open popover". In Chrome, the popover appears as expected. In Safari, both anchored elements (the box and the arrow) are out of position. Here's a real world example - click the superscript 7
https://jakearchibald.com/2025/give-footnotes-the-boot/#:~:text=entirely%20without%20JavaScript
,. - in this case the position is so wrong the content isn't visible at all.
Attachments
Chrome screenshot
(35.92 KB, image/png)
2025-07-02 01:29 PDT
,
Jake Archibald
no flags
Details
Safari screenshot
(43.49 KB, image/png)
2025-07-02 01:29 PDT
,
Jake Archibald
no flags
Details
Reduced repro screenshot in 297085@main
(19.78 KB, image/png)
2025-07-08 00:58 PDT
,
Kiet Ho
no flags
Details
Video of issue
(7.14 MB, video/mp4)
2025-07-08 04:03 PDT
,
Jake Archibald
no flags
Details
Reduced case
(639 bytes, text/html)
2025-07-10 18:01 PDT
,
Kiet Ho
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Jake Archibald
Comment 1
2025-07-02 01:29:47 PDT
Created
attachment 475740
[details]
Safari screenshot
Jake Archibald
Comment 2
2025-07-02 03:01:42 PDT
Actually, it's seems there's more to this than in the reduced case.
https://jakearchibald.com/2025/give-footnotes-the-boot/#:~:text=entirely%20without%20JavaScript
, is a better example to look at (click the superscript 7).
Radar WebKit Bug Importer
Comment 3
2025-07-02 18:06:27 PDT
<
rdar://problem/154908754
>
Kiet Ho
Comment 4
2025-07-08 00:57:54 PDT
Hello, thanks for reporting this. Please note I'm doing this analysis on trunk-ish (
297085@main
), which is ahead of STP (STP 222 is up to
295967@main
). I've attached a screenshot of the reduced repro running in
297085@main
. About the reduced repro (
https://codepen.io/jaffathecake/pen/ZYGNyzr?editors=1100
) 1. What's the point with "justify-self: anchor-center;" on .footnote-popover-content? In Chrome, it doesn't do anything (removing it doesn't change the output). In Safari, it center-aligns the popover with the button, which seems to be expected behavior? 2. When removing "justify-self: anchor-center;", there's still a rendering difference between Chrome and Safari, but for a different reason. In Chrome, popovers have "overlay: auto". According to CSS Position 4, overlay:auto does the following: "Rather than generating boxes as part of its normal position in the document, it generates boxes as a sibling of the root element, rendered "above" it.". So the initial position of the popover (without "bottom: anchor(top)") is at the top-left corner of the viewport. Then "bottom: anchor(top);" aligns the popover to be above the button, and the margin helps line it up vertically with the button. In Safari, "overlay: auto" isn't implemented (see
bug 276727
), so the popover is initially positioned at the "normal" position (as if it's not a popover). So its initial position is to the right of the button. "bottom: anchor(top)" aligns the popover to be above the button, but then it'll be on the right of the button and not vertically lines up with the button. The CSS code used to position the box then makes assumptions about where the initial position of the popover is, which leads to the rendering difference. If you change the positioning code for .footnote-popover-content to be bottom: anchor(top); left: anchor(left); margin: 0 0 var(--arrow-size); then it renders identically in Chrome and Safari
Kiet Ho
Comment 5
2025-07-08 00:58:37 PDT
Created
attachment 475818
[details]
Reduced repro screenshot in
297085@main
Jake Archibald
Comment 6
2025-07-08 04:03:23 PDT
Created
attachment 475819
[details]
Video of issue
> 1. What's the point with "justify-self: anchor-center;" on .footnote-popover-content? In Chrome, it doesn't do anything (removing it doesn't change the output). In Safari, it center-aligns the popover with the button, which seems to be expected behavior?
From
https://drafts.csswg.org/css-anchor-position-1/#anchor-center
> When using anchor-center, by default if the anchor is too close to the edge of the box’s original containing block, it will “shift” from being purely centered,
This is what you're seeing in Chrome. It avoids centring, since it would overflow the viewport. By allowing the box to overflow the viewport, Safari isn't following the spec. You can see that the Chrome/spec behaviour is desirable, as it means the content is readable.
> In Chrome, popovers have "overlay: auto". According to CSS Position 4, overlay:auto does the following: "Rather than generating boxes as part of its normal position in the document, it generates boxes as a sibling of the root element, rendered "above" it.".
What you're describing is "top layer" which Safari definitely supports, as it's a fundamental part of popover (and is used in other things like dialog, fullscreen, view transitions etc etc). Safari doesn't support the CSS property, but it definitely supports the behaviour.
> …then it renders identically in Chrome and Safari
But that isn't the rendering I'm aiming for. I've attached a video that hopefully explains the details better. I wasn't able to test trunk as it just kept telling me various component weren't signed so I wasn't allowed to run them. Is there a guide to getting this working? There was a readme in the package, but it seems out of date, as following the steps didn't work.
Kiet Ho
Comment 7
2025-07-10 17:59:13 PDT
Hi Jake, thank you for replying. My initial reply was after a quick look at the bug, so there was some stuff that I was wrong about. As for the reduced demo (
https://codepen.io/jaffathecake/pen/ZYGNyzr
), this is about anchor-center not shifting as you said. This is tracked in
bug 294575
and was fixed today. From further reducing the reduced case, I also found an issue where boxes in the top layer doesn't use the initial containing block as its static position (it should, per spec). This is tracked in
bug 295686
, but it's probably an accident that I found it and doesn't have anything to do with this bug. As for your site (
https://jakearchibald.com/2025/give-footnotes-the-boot
), the bug is because WebKit is clipping fixed-positioned anchor-positioned element to the viewport, which is wrong and is why the popover wasn't rendered. I have a fix in the works right now.
Kiet Ho
Comment 8
2025-07-10 18:01:01 PDT
Created
attachment 475875
[details]
Reduced case Reduction of
http://jakearchibald.com/2025/give-footnotes-the-boot/
Kiet Ho
Comment 9
2025-07-10 18:45:53 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/47868
Jake Archibald
Comment 10
2025-07-11 01:43:14 PDT
Thank you for taking another look at this. Great to see these fixes landing!
EWS
Comment 11
2025-07-11 18:22:14 PDT
Committed
297297@main
(6ea33a67c88a): <
https://commits.webkit.org/297297@main
> Reviewed commits have been landed. Closing PR #47868 and removing active labels.
Kiet Ho
Comment 12
2025-07-11 19:31:35 PDT
Submitted web-platform-tests pull request:
https://github.com/web-platform-tests/wpt/pull/53740
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug