Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-anchor-position] Allow a positioned el's containing block to be the anchor #11769

Open
jamesnw opened this issue Feb 24, 2025 · 1 comment

Comments

@jamesnw
Copy link

jamesnw commented Feb 24, 2025

After a conversation with @tabatkins, it seems like we may be able to loosen the algorithm for an acceptable anchor.

Currently, given

<div style="position: relative; anchor-name: --a">
	<div style="position: absolute; position-anchor: --a; position-area: start"></div>
</div>

the anchor creates a containing block that is an ancestor of the positioned element, which fails the existing algorithm at ... positioned el’s containing block is an ancestor in the flat tree to that of possible anchor’s containing block.

However, this works:

<div style="position: relative">
	<div style="position: absolute; anchor-name: --a; inset: 0"></div>
	<div style="position: absolute; position-anchor: --a; position-area: start"></div>
</div>

In both cases, the containing block of the anchor has identical dimensions, but because of the DOM order of the elements that generate the containing blocks, the second works while the first fails. Is there a reason why the first couldn't work as well?

In other words, could a positioned el's containing block be generated by the anchor? Could we change the algorithm to read positioned el’s containing block is not a descendant in the flat tree to that of possible anchor’s containing block?

@tabatkins
Copy link
Member

Yeah, I'm pretty sure this is basically just an off-by-one error in the anchor-determining restrictions. The CB is already sized and positioned by the time you're laying out abspos children (modulo the presence/absence of scrollbars, which is already handled due to its inherent cyclicness), so you should be able to depend on it, and the use-cases for it are pretty clear and obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants