-
Notifications
You must be signed in to change notification settings - Fork 669
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-contain-3] Provide a syntax to query a specific container-type #6393
Comments
Maybe something that reflects the container shorthand syntax? @container (inline-size style / sidebar) (width > 30em) and (--card: small) {
<<stylesheet>>
} |
For the shorthand-like proposal, I assume it should be possible to only specify a name or only specify a type? In that case we would need to exclude
Validate its existence somewhat by also having
Maybe it helps to demand parens, i.e. make the grammar
Although one thing to watch out for here is that if |
I like the idea of keeping the name/type syntax in the |
A few options for a shared shorthand… Our current /* using the current `/` divider */
@container inline-size / my-name ( width > 30em ) { … }
@container inline-size ( width > 30em ) { … }
@container / my-name ( width > 30em ) { … }
/* using a single keyword, still ordered */
@container inline-size as my-name ( width > 30em ) { … }
@container inline-size ( width > 30em ) { … }
@container as my-name ( width > 30em ) { … } But that order was based on the assumption that a type is required, and names are optional in the shorthand. That assumption is clearly false in the @container for inline-size as my-name ( width > 30em ) { … }
@container as my-name for inline-size ( width > 30em ) { … }
@container for inline-size ( width > 30em ) { … }
@container as my-name ( width > 30em ) { … } But the more I stare at this, the more tempted I am to just use dashed-idents for names, and allow the two values to mingle completely: @container inline-size --my-name ( width > 30em ) { … }
@container --my-name inline-size ( width > 30em ) { … }
@container inline-size ( width > 30em ) { … }
@container --my-name ( width > 30em ) { … } That might also allow us to express and/or combinations, maybe with the @container inline-size and --my-name / ( width > 30em ) { … }
@container (--my-name or --other-name) / ( width > 30em ) { … } We could consider adding parenthesis around any of these options, if it helps. |
We don't really use preposition syntax markers outside of functions (at least not yet), and using --custom-property syntax here also feels kinda weird. What about:
You'd get things like this:
which doesn't seem unreasonable. |
I like this direction, giving |
I think there are two or three potential consecutive resolutions here:
|
If that were the case, that would solve Higher Level Custom Properties that were talked about late 2020, no? If I interpret things correctly, the there proposed Furthermore, if all elements were style containers by default, is Regarding the syntax itself: I feel that there's some tight clinging onto the IIRC there is discussion somewhere that warned/decided against introducing a lot of new at-rules, so I can definitely understand. From an author's POV however, it feels a bit weird though. I think this "weirdness" stems from the fact that viewport media queries ( My initial reaction to container queries is the same: using What I'm trying to say here: as an author, this piece of code would be highly readable, even if I wouldn't know the exact details about style or container queries: .item {
--effect: none;
…
@style (--effect: fancy) { /* targets self */
…
}
@container (width >= 20em) { /* targets closest parent with size containment */
…
}
} A version that uses Given this last confusion I'm raising here: yes, this could be seen as a plea for keeping Apologies if I'm sidetracking here, or if I'm raising things in here that were already discussed. Feel free to ignore what's not relevant, I know you all will make the correct decisions in the end :) (Congrats on hitting FPWD BTW! 🎉) |
That seems right to me.
Specifying the container-type isn't required in the current syntax, and (as you note) @container style(--effect: fancy) {…}
@container size(width >= 20em) {…} I think that's already pretty readable? What I like about @container card style(--effect: fancy) {…}
@container article size(width >= 20em) {…} If we say that every element is a style container, then there would be no reason to ever use
There is nothing about the word "container" that implies size, so this would only be true for authors with a strong historic attachment to "container queries" as an Idea. That seems to me like a very focused and temporary issue, easily overcome by some good resources. |
Thanks for clarifying, Miriam. I was a bit confused about the functions part because the examples in the ED don't use it. For example, I see: @container card (inline-size > 30em) and (--responsive = true) { … } The definition for
So if I understand correctly, and if this change gets accepted, the snippet above would become this: @container card size(inline-size > 30em) and style(--responsive = true) { … } That's correct? (As long as this issue is still open, I can see why the examples aren't updated yet. No worries)
I know what I'll be explicitly mentioning whenever I get to talk/write about them :) |
Yes, that's correct. I'll make sure to update the examples at some point here.
haha, great! |
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> Topic: CSS Conditional L3 : Syntax for container types<fantasai> github: https://github.com//issues/6393 <fantasai> miriam: Really wanted a way to query which type of conainer <fantasai> miriam: e.g. find nearest inline-size container <fantasai> miriam: Already the query has two parts to it <fantasai> miriam: can query a specific named container <fantasai> miriam: and then main query list is what queries against that container <fantasai> miriam: so adding to preamble ability to filter by container type <fantasai> miriam: in the discussion fantasai suggested that we could matched the syntax of the container shorthand property <fantasai> miriam: currently that syntax requires a type, and then slash, and then any number of names <fantasai> miriam: that could work, but in our initial formulation the container type is required to establish a container <fantasai> miriam: which is why it's first <fantasai> miriam: but for queries, seems that putting name first makes sense <fantasai> miriam: since most ppl will be querying name, not type <fantasai> miriam: Also discussion that all boxes can be style containers <fantasai> miriam: which would make type container <fantasai> miriam: make a style conainer <fantasai> miriam: in that case, we could start with names in container property <fantasai> miriam: and if you wanted to make a type of container without a name, would have to start the value with a slash <fantasai> Rossen_: Any opinions? <miriam> this comment lays it out: https://github.com//issues/6393#issuecomment-988216116 <fantasai> miriam: Comment summarizes the proposal <fantasai> miriam: 3 resolutions <fantasai> miriam: 1. Make style as the default container type, all boxes can take <fantasai> miriam: 2. Changing 'container' property syntax to name / type <fantasai> miriam: 3. Changing @container preamble to match <fantasai> florian: I think we shoud take all 3, only make sense if we take them all <fantasai> Rossen_: Any objections to resolving on all 3? <fantasai> RESOLVED: Boxes default to style containment, syntax of 'container' and @container preamble is name / type <fantasai> Rossen_: Do we need to republish soon? <fantasai> miriam: need to make some changes first |
I don't think we should default everything to being a style container. This came up with currentBackgroundColor Consider the following:
If I wanted to change the color of the Setting explicit containers works better in this case, and setting |
While having all elements default to style containers can cause issues for non-inherited properties (like @una's background-color example), I think it works out great for inherited properties: checking the parent font size, or current font-style, weight, color, etc. Those use-cases are very handy for solving style-toggle use cases (if parent is italic, child should be normal, and vice versa). For use-cases where it's important to query a specific container (including user-defined container types like 'containers with backgrounds'), setting a I'm happy to revisit this if we want to put it back on the agenda (or discuss it as a part of resolving #6644), but at this point I still think we made a reasonable decision. |
My main issue with this is I just don't think it's a reasonable default to assume that a user wants to query the style of a direct parent in a container query. In my current experience with CQ, the majority of my demos and use cases do not query the direct parent. To help illustrate: CQ Card
in: Button Component Inside CQ Card
|
In #6644 (comment), we resolved to remove type from the preamble
|
I split out the remaining questions here into a new issue #7066. Closing this issue as resolved, as we've decided to remove container-type selection syntax, and rely on automated container-type selection. |
The draft Container Query spec describes the container query syntax in two parts:
Which resolve in two distinct steps:
<<container-name>>
)<<container-query-list>>
If no eligible container is selected, the query evaluates to
false
.If the selected container in step 1 is not a valid container type for the query features used in step 2, then the query evaluates to
unknown
. For example, if we try to query ablock-size
container-type about itsinline
dimensions, that measurement is unknown.That means authors will likely also want to filter and select containers based on container type – eg find the nearest
inline-size
container in step 1, in order to query itswidth
in step 2. And, since a<<container-query-list>>
could combine multiple different features, we might need to select for more than one container type.Since container-names are custom identifiers, and container types are built-in keywords (with potential for new additions later on) we'll need some way to distinguish them — either by requiring dashed-idents for names (not a great option), or by adding distinct syntax for selecting each one in the
@container
rule. Something like:type()
function, or a better name for that function?@container
rule?The text was updated successfully, but these errors were encountered: