-
Notifications
You must be signed in to change notification settings - Fork 667
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-view-transitions-2] Specificity of view transition pseudos with classes #9887
Comments
If we defined that |
I am a bit concerned that authors will have a hard time understanding this if this has different rules and weights than regular selectors for things that look similar to regular class, type selectors Specificity is already one of the least well understood parts of CSS. |
They look similar to type selectors just because we didn't add a |
Is it too late to change that? :) |
Sorry, my earlier comment was wrong. There is an actual conflict between IDs in regular space and pseudo space. |
I think the confusion here, at least it was for me initially, is that we're not talking about the specificity of the argument inside I agree that in the pseudo space, the solution is pretty simple: id is id-like and each class is class-like. When bringing that to the regular space, there needs to be some mapping. One idea that came up is to maybe introduce another tie-breaker category of specificity. That is, instead of |
Why shouldn't the specificity just be reflected straight into normal specificity, as ID and class values? These are, by definition, not fighting with any non-VT styles. The only concern, I guess would be that it would mean Is there any potential for other functions we might want to give a weak, tie-breakery notion of specificity to? |
Yeah, that's the only reason why reflecting straight into normal specificity is questionable.
This is something that I'm struggling to answer. Personally, it makes far more sense for I can't picture a scenario where that should not be the case, but that's not to say that those cases don't exist. |
The only thing that's clear to me is that when the external selector has a tie, the internal one should work, as in In terms of mixed-spaces, envision the following css; html:has(.loaded-hero)::view-transition-group(*) { animation-duration: 1s; }
html::view-transition-group(*.box) { animation-duration: 100ms; } I'm not sure I'd expect from seeing this that the duration should be 1s because normal classes receive precedence over vt classes. And I'm not sure we can find any solution that would meet expectations in a self-explanatory way TBH. So the best we can probably do is be consistent with the existing sometimes-surprising behavior and just pick something, probably vt-name maps to ID and vt-class maps to class, and recommend that people use layers if they need things to be different. |
Yeah, that's my concern here - sometimes, the non-VT-pseudo part of the selector is gonna be the more meaningful part and should be paid attention to regardless of the VT argument, and sometimes the opposite will be true, and I'm not sure either is sufficiently obvious as a default. So yeah, while my first suggestion would be to just give the VT pseudo a standard, flat specificity regardless of argument, if we do want tie-breaking to still occur, then just letting the names and classes contribute to normal specificity seems reasonable here, since there are various ways for authors to control this as they need. |
Time for a new specificity category?
That way:
(Oh, did I just nest specificity? 🙈) |
Yeah, that was Vlad's idea. However, that presupposes the answer to my question - it implies that the non-VT part of the selector should always win if it can, and we only look at the VT part when there's a tie. |
Discussed this internally and could not reach a clear consensus. In the spirit of "arguing for the other side", I found the following arguments in support of parameter directly affecting specificity of the selector: From https://drafts.csswg.org/selectors/#matches-pseudo
From: https://drafts.csswg.org/css-scoping/#host-selector
From https://drafts.csswg.org/css-scoping/#slotted-pseudo
From https://drafts.csswg.org/selectors/#nth-child-pseudo
However, specificity of More importantly there is no prior attempts at the tie-breaker specificity, whether or not it may make sense for some of the selectors above. One thing to note is that most of these selectors above are "structural" in that their arguments make sense outside of the argument as well. For example, the parameter in |
Summarizing the internal sync, there was no clear consensus. There seems to be advantages to adding new specificity levels for the pseudo-element's internal argument, but it's unclear if the advantages of that outweigh the cost and whether this would adhere better to developer expectations. Proposing to resolve between the two options at the CSSWG (F2F?). |
What if things are flatter and all worth 1 (except for *)? /* 1 */ ::view-transition-group(foo) /* foo view transition name with any classes */
/* 2 */ ::view-transition-image-pair(*.bar) /* any view transition name with a "bar" class */
/* 3 */ ::view-transition-old(foo.bar) /* foo view transition name with at least class "bar" */
/* 4 */ ::view-transition-new(foo.bar.baz) /* foo view transition name with at least "bar" and "baz" classes */
This would make the author experience less about specificity and more about being specific about the targets. Targeting a pseudo by name already reduces the targets of the selector by a lot, so I don't think it needs higher specificity when it's already so scoped. I see an issue being between #1 and #2 though in that order in the stylesheet would be needed to resolve the final styles. So, i think authors could adjust the selector to be more like 3 or 4, compounding the class with the VT name to "win" and get the end style they want, and thus not needing to worry about rule order. The power is in their hands without needing to learn a new scoring edge case dealing with VT names/IDs. Lean into compound selectors instead of a new specificity system? |
This doesn't answer the question of "1 what"? Is it equivalent to 1 class/type/id/something new?
I don't understand why this is a "strong filter". It means that if you put (1) and (2) they would resolve in document order. |
I discussed this with Adam earlier today and it would be 1 type. I think it could actually work:
|
OK interesting proposal! A bit hard for me to come to terms with |
The CSS Working Group just discussed
The full IRC log of that discussion<TabAtkins> vmpstr: We have VT pseudos that take a paramter<TabAtkins> vmpstr: take name, *, and now classes <TabAtkins> vmpstr: makes the arg syntax more involved <TabAtkins> vmpstr: before classes, specificifity of the pseudo was 0 if *, and 1 tag-like specificity if it took a name <TabAtkins> vmpstr: with classes, should probably change a bit. a few options <TabAtkins> vmpstr: First option, and front-runner, is have every non-asterisk token count as a tag for specificity. just add them up <TabAtkins> vmpstr: minor problem here is having a name and a class has the same specificity. only downside. <TabAtkins> vmpstr: Second option is have the name be ID-like and class be class-like <TabAtkins> vmpstr: This is also simple, and similar to :has()/:is() <TabAtkins> vmpstr: counter-argument is :has/is are more structural, this is specifically a VT element <TabAtkins> vmpstr: Last option is to use the argument just as a tiebreaker <bramus> q+ <khush> q+ <TabAtkins> vmpstr: so you use the argument solely if selectors entirely tie. <TabAtkins> vmpstr: a bit more complicated to spec and implement <TabAtkins> vmpstr: I initially thought the tiebreaker is best, but I'm convinced now it's more complex than necessary. I think option 1 is good enough, where every token is just a tag-like for spec. <miriam> ack bramus <TabAtkins> bramus: I'm on board with Vlad - option 3 was my first, but option 1 is easy to comprehend. <TabAtkins> bramus: I dont' think option 2 is viable since you're changing existing beahvior <TabAtkins> bramus: often authors today are adding a clause to the root to flip the animation direction <TabAtkins> bramus: that adds a class-like specificity to make it win <TabAtkins> bramus: If we change to have the name be ID-like, it could override those. so it's a breaking change <miriam> ack khush <TabAtkins> khush: echoing Vlad, if we made an ideal choice we'd add a new specificity term <fremy> q? <fremy> q+ <TabAtkins> khush: the pseudo arguments are just what specific pseudo you're selecting, my intuition it's less important than what element is being targeted for the pseudo <TabAtkins> khush: but it is indeed a lot more complex, and so just doing Option 1 is fine <TabAtkins> khush: I'm the one that suggested giving the name ID-like spec, but we have already specced different beahvior indeed <TabAtkins> khush: one nice thing is the another feature for VT types lets you not rely on outside elements to select. hopefully that can reduce the issue with specificity - you'll generally just use the VT type only <khush> q? <miriam> ack fremy <TabAtkins> fremy: Is this even required? <TabAtkins> fremy: current behavior is just [0,0,0] or [0,0,1] <TabAtkins> fremy: If you do that you can just order them in your stylesheet as needed <TabAtkins> fremy: Is there really a use-case for having them implicitly ordered somehow? Just wondering if it's even worth increasing the specificity <TabAtkins> vmpstr: good question. if you order them correctly in your stylesheet - we still have to say what happens if you specify a class but not a name <noamr> q+ <TabAtkins> vmpstr: But adding them to get a larger count is optional, sure. If just feels more specific if you add more class names, or class+name, then just adding a name by itself <TabAtkins> vmpstr: So just adding them up is probably Good Enough and somewhat intuitive <TabAtkins> fremy: Yeah, just something new to learn. if it's not required, might be okay to just do nothing new <TabAtkins> vmpstr: So your proposal is just "anything but asterisk is [0,0,1]" <TabAtkins> noamr: And that doesn't compete with HTML in the selector <miriam> ack noamr <TabAtkins> vmpstr: And then your tiebreaker would be declaration order <TabAtkins> bramus: i'm not sure if having asterisk 0 and anything else be 1... <TabAtkins> bramus: i can imagine a scenario "all .card animate one way, but one specific card animate another" <khush> q+ <miriam> ack khush <TabAtkins> vmpstr: if that specific one is targeted with a name, wouldn't fix things - still would be [0,0,1] <TabAtkins> khush: yeah intuitively you might write ::vt(special-card) and ::vt(.card), expecting first to win, but that's a harder model to specify <TabAtkins> khush: So maybe better here indeed to just rely on name ordering <vmpstr> proposal: for view transition pseudos, have * argument as 0 specificity, and everything else 1 type like specificity <TabAtkins> miriam: objections? <TabAtkins> RESOLVED: for view transition pseudos, have * argument as 0 specificity, and everything else 1 type like specificity |
… with a class Closes w3c#9887 See [resolution](https://github.com/w3c/csswg-drafts/9887#issuecomment-1939286361)
… with a class Closes w3c#9887 See [resolution](https://github.com/w3c/csswg-drafts/9887#issuecomment-1939286361)
… with a class (#9941) * [css-view-transitions-2] Amend specificity of view-transition pseudos with a class Closes #9887 See [resolution](https://github.com/w3c/csswg-drafts/9887#issuecomment-1939286361) * Reword specificity * Fix cruft * Reframe
in #8319 we've added
view-transition-class
that reflects in the view transition pseudo tree, so things like the following become valid selectors:The question here is which specificity should these view transition elements have. Some points to consider:
One off-the-top of the head proposal is something like:
class-like-specificity * (5 * id-is-present + number-of-classes)
meaning that the following holds:
::view-transition-group(*)
remains 0The worry of course is that 5 classes is as specific as 1 name. We could make the constant higher like 10 or something, but there's also a worry that
::view-transition-group(foo)
would become 10 class-like specificity which is pretty high if we combine this with other class like selectors. For example:would be higher specificity (I think) than
which also seems wrong
We can have our own specificity ordering within the argument, but how it maps to outside of the argument is unclear
/cc @tabatkins @fantasai for question whether there's prior art here
The text was updated successfully, but these errors were encountered: