-
Notifications
You must be signed in to change notification settings - Fork 719
[css-cascade-5] Allow authors to explicitly place unlayered styles in the cascade layer order #6323
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
Definitely welcome to have that level of control. If you didn't want a reserved name you could use different @ name. e.g. |
Idk if it's a good idea, but one possibility would be to just leave out the identifier.
|
Thinking about this a bit more: every layer (including but not limited to the default/root layer) has the potential for both direct style-rules and nested sub-layers. So this feature might be useful in nested context, not only in the root/default situation: @layer one;
@layer;
@layer one {
@layer two;
@layer;
} On the other hand, the root/default layer is the only place where authors might not be able to add explicit layering – for the sake of backwards compatibility. Once styles are layered, there is no harm in layering them further. So from that perspective, control is only needed for fully-unlayered styles. Is it confusing if authors can specify different defaults inside each layer context? Is it more confusing if this only works at the top level, and does not work in nested contexts? |
It would be a shame in my opinion if it didn't work the same in nested layers. I'm also not sure how |
The CSS Working Group just discussed
The full IRC log of that discussion |
Given the resolution above, I think we all agree that I'm not sure, but I suspect making the whole rule invalid is safer. Otherwise, we might have people who introduce a |
I'm happy with that approach, and drafted some spec language around it. Not sure if we need to get an official resolution, or not? |
I noted while thinking about this in the context of #6284 that explicitly pinning "initial" as a layer name isn't very convenient, because this has to happen once, and so that first declaration needs to be aware of all the layers that need to be above or below the initial layer (which might not be possible if you are using themes / unrelated add-ons). Another approach I have been thinking about is to have two lists independently, all layers that must be above the unlayered styles, and all who need to be below. A strawman would be as follow (`!important following an at-layer name means to put in the list after unlayered styles):
That would yield the following order for the layers : Adding |
The advantage I see is that we are not prescribing anything here about the specifics of the default, authors can get one or the other depending on their needs. |
I think it's going to be useful and important to be able to have one-off layer declaration blocks that are above or below the default-layer styles, so we should have a syntax built into the @layer rule that says whether it goes above or below. Something like:
where
|
I like the goal here, but have a few questions. As I understand this, we would basically be creating two layer stacks — one above and one below the default — and then use the keywords to append layers to the top of either stack? What's the result of these cases? @layer up one;
@layer down one; Does that give us two layers with duplicate names (upper one & lower one)? Or do we only allow this keyword when the name is first used (in which case the second rule is invalid)? Another option is that we only provide this one-off syntax for truly one-off unnamed layers? In which case we likely need both the explicit placement, and the one-off option.
I assume we don't want to allow moving layers around retroactively, so the second rule should not impact the layers defined in the first rule. That's what |
Given my proposal is to have two independent lists, I guess it's fine to have two layers named "one", one in each list. Another way of seeing this is that one layer would be named "one" and the other "one!important" without préjudice to each other. (Or, you know, "up one" and "down one" if we adopt fantasai's syntax) |
I'm not a big of this "two lists" idea - it makes ordering less obvious (no longer order-of-appearance, but two simultaneously-calculated orders of appearance), and it brings up identity questions like what @FremyCompany referenced without good answers. "One-off" layers that are before/after a specific significant layer are already something authors might want for any layer, but we don't allow that because it's better for the page to declare its layer order up-front; it makes the entire feature more understandable and manageable over time. I don't think the default layer is in any different in this respect. (We do at least let styles arbitrarily inject themselves after a given layer via nesting; an |
Why not. I would be totally fine with
But then maybe "initial" is a strange name for that layer. What are our other options? Unset? |
I don't follow that.
is the same as
except that
is implicit, so is the same as
which is (now) an underpin (down) layer, not an overrides (up) layer. |
No, the point is that, because the initial layer is explicitly named, it's not implicitly removed from the layer stack. |
So one could do |
I suppose that would be the implication, sure? |
Are we moving towards a consensus here?
|
To those looking: here’s the link with the comment with all options: #6323 (comment)
Would prefer to use |
Definitely +1 to
But to me, |
This is the entire reason I would avoid The way this works is more similar to ID selectors being the stronger of the selectors. |
The CSS Working Group just discussed The full IRC log of that discussion |
@hober can you make any argument here that doesn't rely entirely on theoretical purity? Is there any actual advantage to be had for authors, users, implementors, or anyone else if we separate the sigil from the name? |
I believe we were close to settling on As mentioned in the call, the strongness of a layer can be exposed in CSSOM through a new attribute on |
Coherence with the rest of CSS, in particular ID and class selectors. |
That works for me! |
Though this is unfortunate. |
Thanks. Could we:
? |
That tells us that strong layer names and weak layer names live in different namespaces. Maybe the CSSLayerBlockRule attribute name should reflect that, |
But that choice is up to authors to make. Or could also happen by accident: If I author a strong layer |
I hate to re-tread older ground, but looking at past discussions, option 3 was never fully rejected. The tradeoffs of options 2 and 3 were discussed, but no resolution. Option 3 would look something like Benefits:
It was said earlier that option 2 and option 3 are the same (which would make this bikeshed), but the namespace separation is an important distinction between 2 and 3 (at least in my mind). (I'm only mentioning this because it might help with some of the unresolved concerns. Feel free to ignore if it's unhelpful or unviable. I care more about the overall functionality than the specifics.) |
Point two is the most compelling here. That potential namespace collision is the main issue we're left with. (Which seems like a very niche issue to me in practice, since it doesn't come up in the CSS syntax). As to theoretical future layer features (raised here and on the call): There are three and only three positions that are fundamental to cascade layers. Two of them already exist. We can have styles not in a layer (unlayered), and styles below those (default layers). There's only one more position available for completeness – above unlayered styles. There is not some arbitrary number of future positions at this level. If we use Any theoretical future reserved layer names/features would be dealing with a different level of concern – either contained within those three positions, or extending outside them entirely (as most of the existing proposals have). If we want to leave things as flexible as possible for future developments, I would avoid expanding into a new name syntax for these fundamental positions. After following that thread, I'm (personally) back where I was, supporting the existing proposal. |
The CSS Working Group just discussed
The full IRC log of that discussion |
Uh oh!
There was an error while loading. Please reload this page.
Regarding CSS Cascade 5 (cascade layers), @jensimmons commented on another thread about layer ordering:
By default unlayered style come first (lowest cascade priority) in the source order, but this would allow more explicit placement. Roughly (pseudo-code):EDIT: That's no longer the case. In #6284 we reversed the behavior, and now unlayered styles have the highest priority. This explicit placement would still be useful, since there are use-cases for both approaches.
I think that feature makes a lot of sense, and I would likely use it as an author. A few considerations to keep in mind, as we develop a mechanism for this:
The text was updated successfully, but these errors were encountered: