RESOLVED FIXED299950
Anchored elements using position-area are incorrectly shifted vertically to pull them into the viewport
https://bugs.webkit.org/show_bug.cgi?id=299950
Summary Anchored elements using position-area are incorrectly shifted vertically to p...
Ehren
Reported 2025-10-01 05:15:46 PDT
Created attachment 476916 [details] Safari on left, Chrome on right. Overview: If an anchored element is too tall to fit within the viewport at its anchored position, it's shifted upwards in an attempt to display the entire element. This occurs even when there's enough space in the document below the anchored element. Demo: https://codepen.io/eharber/pen/qEbNzya?editors=1100 There is a 50vh element above the toggle which simulates content. The 80vh anchored popover element has plenty of space below it (200vh), so it should occupy that space when it's toggled. Expectation: The menu should be positioned below the toggle button (as in Chrome) Result: In Safari 26.0, the anchored element overlaps the toggle button because it's vertical position has been altered to ensure the element is within the viewport. Screenshot attached showing comparison of Safari and Chrome.
Attachments
Safari on left, Chrome on right. (171.22 KB, image/png)
2025-10-01 05:15 PDT, Ehren
no flags
Poor alignment of position-area:bottom element (253.32 KB, video/quicktime)
2025-10-01 19:47 PDT, Ehren
no flags
Radar WebKit Bug Importer
Comment 1 2025-10-01 09:25:14 PDT
Kiet Ho
Comment 2 2025-10-01 14:35:23 PDT
It seems like it's this behavior in the spec: > If the box overflows its inset-modified containing block, but would still fit within its original containing block, by default it will “shift” to stay within its original containing block, even if that violates its normal alignment. See CSS Box Alignment 3 § 4.4 Overflow Alignment: the safe and unsafe keywords and scroll safety limits for details. > This behavior makes it more likely that positioned boxes remain visible and within their intended bounds, even when their containing block ends up smaller than anticipated. > For example, a position-area: bottom span-right value lets the positioned box stretch from its anchor’s left edge to its containing block’s right edge, and left-aligns it in that space by default. But if the positioned box is larger than that space (such as if the anchor is very close to the right edge of the screen), it will shift leftwards to stay visible. WebKit implements this but not Chrome (yet).
Kiet Ho
Comment 3 2025-10-01 14:35:45 PDT
Ehren
Comment 4 2025-10-01 19:47:48 PDT
Created attachment 476934 [details] Poor alignment of position-area:bottom element
Ehren
Comment 5 2025-10-01 19:51:02 PDT
Thanks for the reply Kiet! Just to clarify, since the spec can be a little overwhelming at times (for me).. Shifting the inline axis, as mentioned in the example above, makes sense. Safari does this correctly, ensuring the popover doesn't overflow the viewport and therefore stays accessible. After this inline shift, the anchor element is still visible/accessible. Does the spec clarify that this shift should also occur for the block axis too? Keeping in mind that the anchor element will be obscured in this case. Attached above is a video demonstrating that even though there's plenty of space below the anchor, the menu still shifts vertically. This shift covers the anchor element (button) and prevents the popover="manual" element from being closed. The Codepen demo from above has been updated to show the implications of this with manual popovers. If this is still correct according to the spec, please let me know. It just seems odd as I was under the impression that anchor elements (the button in this example) should never be obscured, and that the anchored popover element should simply reposition itself *around* the anchor, not *directly on top* of it. Thanks again!
fantasai
Comment 6 2025-10-02 10:21:06 PDT
> Does the spec clarify that this shift should also occur for the block axis too? Keeping in mind that the anchor element will be obscured in this case. Yes. But there is also a provision in the spec that the containing block (the rectangle in which we should be constrained) should be the entire scrollable area in this case. I think we'll need to fix that for this to work correctly.
fantasai
Comment 7 2025-10-02 17:58:07 PDT
EWS
Comment 8 2025-10-02 23:36:24 PDT
Committed 300921@main (6d342d3c33b9): <https://commits.webkit.org/300921@main> Reviewed commits have been landed. Closing PR #51718 and removing active labels.
EWS
Comment 9 2025-10-06 10:43:33 PDT
Committed 297297.512@safari-7622-branch (adaa1a9ab8d4): <https://commits.webkit.org/297297.512@safari-7622-branch> Reviewed commits have been landed. Closing PR #3756 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.