-
Notifications
You must be signed in to change notification settings - Fork 687
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-grid] Do all percentages behave as auto when computing minimum contribution? #3612
Comments
In https://crbug.com/931474 I have fixed Blink to behave like Firefox. |
…m the minimum size rather than the min-content contribution. #3612
OK, clarified the spec by saying "behaves as auto or depends on the size of its containing block in the relevant axis". (Also did some editorial restructuring to make it easier to read.) See https://drafts.csswg.org/css-grid-1/#min-size-contribution @MatsPalmgren I'd appreciate your review! |
@fantasai I don't understand why this change was necessary. What does "or depends on the size of its containing block in the relevant axis" cover that isn't already covered by removing that bit?
All of them are affected while resolving the intrinsic track sizes because the percentage basis for a grid item is the size of its grid area which isn't known at that point (so it's indefinite). The part of the spec that is relevant for this particular testcase is the "preferred size behaves as auto" ( |
@MatsPalmgren I discussed this with @fantasai and @FremyCompany, and seemingly it can only be said that a value behaves as auto when specifying auto instead of that value would have no effect. In this case, a percentage is equivalent to auto while resolving the intrinsic track sizes, but once we know the size of the grid area, the percentage is no longer treated as auto. So the percentage doesn't behave as auto. Therefore, we considered saying "contains a percentage", but this wouldn't cover things like a future |
Exactly. This is what I said.
Are you saying that you don't want to resolve |
It seems I didn't explain well. You said that you don't understand why this change was necessary. It was necessary because here percentages don't behave as auto, so a percentage would fall in the "else" part of the conditional. By adding "or depends on the size of the container" we made the condition hold for percentages. I was just trying to explain why percentages are not considered to behave as auto despite not knowing the grid area yet. The reason is that, once we know the grid area, percentages will behave different than auto. So we can't consider percentages to behave as auto, since it's just a temporary thing. |
I don't like this new incompatible definition of "behaves as auto". The old definition was contextual, meaning that a percentage behaves as auto when its percentage basis is indefinite, otherwise it's simply resolved to a definite length. This is much easier to understand and handle since a percentage is resolved in different situations: for intrinsic sizing purposes, for track sizing contributions, and eventually in layout and you'd use the percentage basis in the local context to determine if it "behaves as auto" or not. It's also very bad to take a well-known and widely used term like this and redefine it with an incompatible meaning. We have code comments, discussions in Bugzilla, dev forums, review comments, CSSWG github issues etc etc where the term "behaves as auto" is used (with the old meaning). Those comments are now wrong and misleading due to this change. The new term "depends on the size of its containing block" is also bad. If we have say: <p style="width: 100px">
<div style="width: 100%"></div>
</p> then the I think the old definition of "behaves as auto" worked just fine. CC @dholbert |
I also had the impression that "behaves as auto" was contextual, but I was told that the definition of "behaves as auto" is that the behavior of the value is completely indistinguishable from Can you clarify why you think this definition is incompatible? I had the impression that percentages being treated as
Yes, that's why we used "depends on the size of its containing block", we wanted to include percentages. Just checking "behaves as auto" wasn't including percentages. |
No, no, no, that has never been the definition of the term "behaves as auto". It was always contextual, i.e. if the percentage basis was indefinite in the particular place you resolve it.
It's always been like that as far as I know. This isn't specific to Grid/Flex layout, a simple float will do: <div style="float:left; border:solid">
<div style="width:200%; background:lime">abc</div>
</div> Here,
To be clear, I said that the new definition of "behaves as auto" is incompatible with the old definition of "behaves as auto" (not that the whole new term is necessarily incompatible, although that's also true). The old definition of "behaves as auto" includes percentages resolved against an indefinite percentage basis whereas the new definition of "behaves as auto" does not. From the top of my head, I can't think of a single case where a percentage size does not have a definite percentage basis at least at some point, so percentages never "behaves as auto" with the new definition AFAICT. Thus these two definitions of "behaves as auto" are clearly incompatible. I assume this is why "or depends on the size of its containing block in the relevant axis" was added - to capture percentages. However, that term captures too much since all percentages depend on their percentage basis (i.e. "size of its containing block"). (also If you change the new term to "the size behaves as auto or is a percentage with an indefinite percentage basis" then that would be compatible with the old definition of "behaves as auto". This new definition is more cognitively complex though, because now you have one part that is non-contextual ("behaves as auto") and one part that is contextual ("percentage with an indefinite percentage basis"). It's simpler to say that "a percentage with an indefinite percentage basis" behaves as auto.
OK, but you also need to avoid including
Right, the new definition of "behaves as auto" never includes percentages AFAICT. |
OK, not restricted to Grid/Flex. I guess your example with
For example,
This is true in general, but at this step of css-grid the percentage basis is never known, so capturing all percentages seems fine. We can't have Anyways, for discussing the exact definition of "to behave as auto" it may be better to file a new issue against css-sizing. |
But the behave as auto is in css-sizing, not CSS2. I always understood css-sizing as applying to all of CSS.
Well, floats are in CSS2, so the float example I gave demonstrates there is, right?
True, but note that an auto-sized block's block-size is still indefinite when resolving the child's used value of
What about the block layout example I gave above? We need a general definition that works for that case too. It's also worth noting that in resolving intrinsic row sizes, the grid area sizes are definite in the column axis so some transferred sizes (e.g. images with a ratio) involving percentages are resolved.
Fair enough, I just don't see a reason to change what is already a working definition. Especially since it's a long-standing and widely used term and thus changing it invalidates all prior discussion and comments involving this term (as I described above). |
The definition of “behave as auto” was added in #1051 and it is very explicitly linked to the behavior in CSS2.1 where a percentage behaves as auto exactly as if its computed value were auto throughout all phases of layout. (This is the only example that is called out in the definition.) Now, if this terminology is confusing (I'm personally not a fan) and we want to use some other terms for this behavior, that's fine. We can change it. But I don't think it's factually correct to say that it was always defined contextually, as you are asserting, @MatsPalmgren. |
Spec fix: bf1450a
|
From https://drafts.csswg.org/css-grid/#algo-single-span-items,
Percentages in preferred size are resolved with respect of the grid area. The grid area is being calculated, so I guess all percentages should be considered to behave as auto?
The change was done in #2367 as an Obvious Bugfix. Well, it doesn't seem that obvious to me, because the change was against the behavior of all Blink, Firefox and Edge at that time (Firefox later adapted to the spec in https://bugzil.la/1462854). In this example, there is no longer a green background in Firefox, but there is in Blink and Edge:
I just want to confirm whether my understanding of the spec is correct and whether this implication was intentional. In #2367 @MatsPalmgren said "percentages should behave as auto when the percentage basis is indefinite" like implying only some percentages were affected, but it seems to me that all of them are affected.
The text was updated successfully, but these errors were encountered: