-
Notifications
You must be signed in to change notification settings - Fork 670
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-position-3] Incorrect handling of auto inset properties in absolute positioning #11242
Comments
No. As per https://www.w3.org/TR/css-position-3/#abspos-auto-size
|
I'm not sure whether this should be interpreted as a contradiction or a specialization of point 2 in 4. In any case, it doesn't explain why the |
Mm, yeah. So I think we have to options:
The difference is observable when setting the self-alignment to e.g. |
This feels a bit complex to me. Introducing a dependency where the dimensions of the inset-modified containing block (IMCB) depend on the dimensions of the absolutely positioned box (abspos) adds a layer of interaction that doesn’t exist in the current definition. If the abspos overflows the absolute-position containing block, the IMCB would overflow as well, and its position becomes unclear—especially with mixed auto and non-auto inset values. What I propose is:
What do you think? |
Well, it does exist in the CSS2 definition, and CSS Position is supposed to be backwards compatible with it.
I think
This needs to be handled via CSS Align. It could only be about |
Could you include a link to the relevant CSS2 section?
Admittedly, I'm not entirely clear on this. I tested using both |
https://drafts.csswg.org/css2/#abs-non-replaced-width resolves
Yes, that's why I said that browsers seem to use the 2nd option. If they were doing the 1st option then the abspos would be aligned within the alignment container, which is the inset-modified containing block in this case. |
This seems like a pretty different approach compared to the current spec. In the CSS2 model, the inset properties are basically just offsets from the edges of the containing block that position the abspos element but there’s no mention of top/bottom in this context. In the current spec, though, the inset properties define the size of the reduced containing block—the inset-modified containing block (IMCB)—and the abspos element is positioned inside it. But figuring out the exact position of the abspos element within the IMCB is a separate issue. That said, the current spec definitely needs to stay compatible with the expected CSS2 outcomes. But I’m not quite following your suggestion:
How do you figure out the abspos element’s initial position to base the IMCB offsets on? The inset properties are supposed to define the offsets of the IMCB, not the abspos itself, right? It feels a bit circular—can you clarify? |
https://drafts.csswg.org/css2/#abs-non-replaced-height
|
|
In the current spec, the However, the same spec section states, by implication, that if the abspos element has an Example: Consider the following code. Any of the images below could represent a legitimate rendering: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
#parent {
position: relative;
width: 200px;
height: 200px;
border: 5px solid black;
}
#child {
position: absolute;
background-color: yellow;
top: 0;
right: 0;
/* bottom: auto → 0 (spec 3.1. Box Insets) */
/* left: auto → 0 (spec 3.1. Box Insets) */
}
</style>
</head>
<body>
<div id="parent">
<div id="child">BOX</div>
</div>
</body>
</html> To resolve this, additional meaning would need to be added to I propose reverting the current |
The alignment within the IMCB is determined by CSS Align as I already said.
I think it was added as part of the CSS Position overhaul of the CSS2 logic, which was trying to simplify the logic in a way that properly handles direction, writing mode, alignment, etc. But ask the editors who added it.
Not in general.
Yes. This doesn't require auto insets.
No, if the IMCB has a different size than the abspos, you just use CSS Align properties. At most you can affect the resolution of a
CSS2 doesn't handle lots of modern things, like alignment. |
But it doesn't work in Chrome or Firefox. We already discussed this (align-self: center; and justify-self: center;), so what's the point of bringing it up again?
Yet another positioning issue remains unaddressed.
We are talking about the very essence of positioning in CSS. Do you really think it’s reasonable to redefine the entire semantics of absolute positioning and expect adoption? I’ve read every point in the CSS2 spec you referenced—it’s mathematically precise. The information in the current spec doesn’t even come close to that level of detail. |
No, it works, as you can see with non-
No, see above
Yes, as long as it's backwards compatible.
Being precise in the scope of CSS2 is useless if it doesn't handle the interaction with new CSS features. |
What do you mean by Firefox Nightly? It doesn’t work in the most recent version of Chrome! I feel like we’re talking past each other... Is the 'current spec' about a 'potential future CSS'? Which spec is considered authoritative for what is currently supported by browsers? |
https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly
It works, see some examples in servo/servo#34226
Sometimes? Not sure if you have noticed that CSS Position 3 is a Working Draft, it's not a Recommendation yet. The CSS Snapshot 2024 classifies it as a "module with rough interoperability"
|
This doesn't work in Chrome, which is the entire point of this issue. <!DOCTYPE html>
<div style="position: relative; width: 100px; height: 100px; border: 3px solid">
<div style="position: absolute; align-self: center; justify-self: center; background: cyan; height: 25px; width: 25px; inset: auto 0 0 auto"></div>
</div>
Understood. In the meantime, I think I’ll stick to what has been tested and proven to work. |
No it's not the entire point. You want to make CSS Align properties do nothing on abspos because they didn't exist in CSS2 and you wrongly claim that browsers don't support them. You are of course free to stick to CSS2 for whatever you are doing, but here we are trying to decide how the language will evolve. This conversation is not productive so I will stop. |
@gitspeaks wrote:
Please don’t misrepresent what I said. I provided two examples in this issue that demonstrate the CSS Align properties don’t work in the most recent browsers under the conditions described in this issue.
I agree. The conversation should focus on refining the definition so that both CSS2 and CSS3 users can use absolute positioning as described in their respective specifications. This discussion is not about what is available in 'Nightly.'
I have demonstrated very clearly a deficiency in the spec regarding absolute positioning. If CSS Align properties provide a resolution in the future, so be it. However, the larger issue here is that we now have two completely different models for absolute positioning running concurrently. That, my friend, is bound to create significant confusion for developers. Mark my words. |
For anyone involved in "trying to decide how the language will evolve", please consider how absolute positioning has been taught to millions of developers up until today: MDN introductory course "Learn to style HTML using CSS" "notice that the position of the element has changed. This is because top, bottom, left, and right behave in a different way with absolute positioning. Rather than positioning the element based on its relative position within the normal document flow, they specify the distance the element should be from each of the containing element's sides. So in this case, we are saying that the absolutely positioned element should sit 30px from the top of the "containing element" and 30px from the left." Source: https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning |
@fantasai , @tabatkins could you please share your perspective on this issue? |
Spec References
3.5.1. Resolving Insets: the “Inset-Modified Containing Block”
3.1. Box Insets
Scenario
Expected Behavior
According to the spec, the inset properties
left
andbottom
, being exclusivelyauto
in their respective axes, should compute to0
. This means:With
top
andright
explicitly set to0
, the#parent
div defines an inset of 0 on all sides, meaning the inset-modified containing block will match the dimensions of the absolute-position containing block (e.g#parent
div).The
#child
div should size itself to cover the maximum available space, filling the#parent
div entirely.Actual Behavior
In both Chrome and Firefox:
#child
div sizes itself to fit its inline content.#parent
div padding edge.This behavior contradicts the specification, as the unset inset properties (
left
andbottom
) are resolved to non-zero values.Note:
This behavior persists even when explicitly setting
left
andbottom
toauto
, instead of relying on their implicit initial value ofauto
.Explicitly setting all inset properties (
top: 0; right: 0; left: 0; bottom: 0
;) causes the#child div
to correctly cover the#parent
div, showing that the behavior works as expected when noauto
values are involved.The text was updated successfully, but these errors were encountered: