-
Notifications
You must be signed in to change notification settings - Fork 707
[css-contain] Can we allow absolutely positioned elements to escape a container? #10102
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
Comments
Given that top layer lets us do this already, I assume that the core functionality of "move this element around in the box tree" is at least feasible. What I'm not clear on is if there are complications that make it difficult to go anywhere between "use the normal CB" and "use the topmost possible CB".
I think it's just because of static positioning - figuring out the static position requires doing layout on the subtree, and that would defeat the layout-containment optimization. We'd have to zero out the static position if we did something with this. (Which isn't a problem for anchor positioning, obviously.) I think that's similarly why things like transforms create fixpos containing blocks - if the static position isn't transformed, then it's just a nonsense position with no relation to anything, but if it is transformed, then it could become an unaligned non-rectangle wrt the fixpos element, which isn't meaningful for static positioning either. So yeah, in all cases I think it's fine to let an element move its CB higher in the tree, so long as it loses its static position in the process (just goes in the start/start corner or something instead). |
I think that would be an acceptable tradeoff in most cases. |
Don't we also have an issue if we let abspos escape their containment that they could overflow some ancestor, create scrollbars, and thereby affect the layout of the rest of the page? |
Right, that would potentially be one of the «complications that make it difficult to go anywhere between "use the normal CB" and "use the topmost possible CB"» |
A side comment, but I think for transforms the difference is also semantic. If you're rotating the "contents of an element", how does that affect the position of something in that element's subtree that's actually positioned relative to something outside of the subtree? Does it escape the transform? Does it instead add up the translations out to what it's relative to and then subtract back in to the transformed element, and then transform as though it had that translation from the transformed element? On the main issue here: the underlying request here seems reasonable to me, though, as long as it's not anchoring to something that's inside a container that the positioned thing is outside. It's less clear to me what is the right way to move definitions/terms around to get that result. |
I've filed #10544 which tries to solve this issue (and others) slightly more generally. |
That doesn't work. When you add According to https://developer.mozilla.org/en-US/docs/Web/CSS/position, any element with If you change this, you need to remove item 4 from the specification described at https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block Identifying the containing block
You can also mitigate this problem by using It broke in Chrome with the latest release - https://issues.chromium.org/issues/369781727 |
The specification that MDN links to explains the same result https://www.w3.org/TR/css-position-3/#intro Absolute positioning, which ignores normal layout entirely, pulling the element out of flow and positioning it relative to its containing block with no regard for other content. The inner element position applies to the containing block when position is absolute. https://www.w3.org/TR/css-contain-3/#containment-types 3.1 Inline-Size containment Giving an element inline-size containment applies size containment to the inline-axis sizing of its principal box. The outer element is a containing block when container is set to inline-size. |
Yes, it's true that the specification is out of date, and needs to be updated. We resolved on that change previously, and the relevant issue is labeled appropriately |
When you set There is no containment specification because containment is arranged based on the order of the containing blocks. |
I'm splitting this out from #10040, where we resolved that
anchor-name
is able to escape containment. That helps authors position elements in relation to contained anchors. But it doesn't help with the inverse: absolutely positioned elements inside a container cannot be anchored to anything outside the container.This mirrors a common footgun with container queries. The container (
layout
containment) generates a fixed positioning context, so position-fixed elements are fixed to the container rather than the viewport.If there is any way to loosen that requirement for container queries, it would remove the footgun and also allow more fluid interaction between container queries and anchor positioning.
I'm not entirely clear why this fixed-positioning context restriction is useful for container query implementations. I would have expected the (already resolved) counter example to be more problematic - since generally we don't want external layouts relying on container internals. In this case we only want internal layout to rely on external context - which is already the case. But maybe my mental model is wrong here?
The text was updated successfully, but these errors were encountered: