Skip to content

[css-anchor-position-1] Interaction with anchor-center and scrolling #9223

@xiaochengh

Description

@xiaochengh

(Split off from #8979 (comment))

The current spec 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 text, or current resolution of #9124, or @fantasai's alternative proposal there) is collapsed, and the element ends up not center-aligned with the anchor, but instead:

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

Discussions

I think the highest priorities are:

  1. Scrolling doesn't trigger relayout, except when fallback position is changed
  2. We should get the same layout for (i) anchors initially in the CB, and (ii) anchors that can be scrolled into CB

And I don't see any way to achieve these two at the same time if we also want to support "fitting the element within the IMCB by shifting it around", which the current spec wants to support.

This proposal also requires 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Friday Afternoon

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions