[csswg-drafts] [css-anchor-position-1] Interaction with `anchor-center` and scrolling (#9223)

xiaochengh has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-anchor-position-1] Interaction with `anchor-center` and scrolling ==
(Split off from https://github.com/w3c/csswg-drafts/issues/8979#issuecomment-1687501139)

The [current spec](https://drafts.csswg.org/css-anchor-position-1/#anchor-center) of `anchor-center` tries to fit the element within the inset-modified containing block without triggering position fallback.

This doesn't work if the anchor is initially outside the containing block and can be scrolled back. In this case, the inset-modified containing block (regardless of how you computed it, via the current spec, or proposals [A](https://github.com/w3c/csswg-drafts/issues/9124#issue-1827118035) and [B](https://github.com/w3c/csswg-drafts/issues/9124#issuecomment-1678174879)) is collapsed, and the element ends up not center-aligned with the anchor, but instead:
- Start-aligned with the anchor per the current spec or [proposal B](https://github.com/w3c/csswg-drafts/issues/9124#issuecomment-1678174879)
- Start-aligned with the containing block per [proposal A](https://github.com/w3c/csswg-drafts/issues/9124#issue-1827118035)

## My proposal

If there's `anchor-center` alignment on an axis, then:
1. Always center-align the element with the anchor without considering insets
2. If the result of 1 overflows the scroll-adjusted IMCB and there are fallback positions, trigger position fallback
   - The scroll-adjusted IMCB should be computed following [proposal A](https://github.com/w3c/csswg-drafts/issues/9124#issue-1827118035), namely, treating any `auto` as `0`

## Discussions

This proposal basically gives up fitting the element within the IMCB by shifting it around, but instead, leaves this part completely to position fallback. The reason is that:
1. We should make sure scrolling doesn't trigger relayout, unless fallback position changes
2. I don't see any way to support "fitting the element within the IMCB by shifting it around", which basically require taking scrolling offsets into IMCB calculation, without causing relayout

This proposal also requires proposal A (i.e., the current resolution) of #9124. The rationale is straightforward: suppose we are positioning a popover (with `position: fixed`), and want it to be center-aligned with an anchor, and trigger position fallback when reaching the viewport boundaries. Then the IMCB is simply the viewport, which is `inset: 0`.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9223 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 22 August 2023 22:00:13 UTC