-
Notifications
You must be signed in to change notification settings - Fork 689
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
[selectors-4]Why Pseudo-elements cannot be represented by the :is()/:matches()
?
#2284
Comments
I guess it can be useful in |
The reason is that pseudo-elements, semantically, contain a combinator in them - if you start with
Further, say you have something like |
It seems to me that since pseudo-elements were allowed to be effectively the subject of pseudo-classing, we can't restrict the effect of pseudo-classing to "subsetting the elements only" anymore. Yes, currently only pseudo-classes of user action are allowed for pseudo-elements, but I agree that @Loirooriol's example could be very useful in many cases. Maybe it would be useful to introduce something like "any pseudo-element" notation that would be combinable with pseudo-classes like |
If I'm reading you correctly, I think you misunderstood what I meant by my previous comment. I'm not drawing any real distinction between elements and pseudo-elements; as far as Selectors is concerned, they're basically the same thing. (This is my entire point above; because a pseudo-element is effectively a new element, the pseudo-element selector is not equivalent in meaning to any other simple selector, and is instead basically a combinator into the "pseudo-children" of an element.)
I wouldn't mind recasting things a bit to add a real combinator into the "pseudo-children", where presumably the pseudo-element names are instead matched as tagnames, like |
@tabatkins I don't say that elements and pseudo-element are fundamentally different, and I like your interpretation of the And I like the idea of treating |
Ah, I dug up the old thread (from 2012!). The parsing problem with reinterpreting First, selectors like However, this requires a new constraint - the descendant combinator (at least in its current whitespace form) can't play with this new chained-combinators feature, or else But this causes another problem! Selectors like So, we're screwed. Some existing selectors require a new feature to be parsed the same, which requires a funky restriction, which causes other existing selectors to not parse the same. The only way around this is to add a totally new combinator for pseudo-children, not |
The CSS Working Group just discussed
The full IRC log of that discussion<dael> Topic: Why \"Pseudo-elements cannot be represented by the matches-any pseudo-class\"?<dael> github: https://github.com//issues/2284 <dael> fantasai: I wanted to ask if this is something we should try and define or close as no change <dael> TabAtkins: Valid. <dael> TabAtkins: I know that safari allows pseudo elements, but it doesn't make sense and I don't know why <TabAtkins> .foo:matches(::before):hover <dael> TabAtkins: This selector ^ bothers me. <dael> TabAtkins: Unclear if it means before when foo is hovered or when foo.before is hovered. <TabAtkins> .foo:matches(::before).bar is invalid, then <dael> fantasai: If we're going to define we have to define if a selecotr ends in a pseudo element and has same meaning as if you placed element outside of matches. <TabAtkins> .foo:matches(::before, .baz).bar is invalid, too <dael> fantasai: That's invalid, right. <dael> TabAtkins: Reasonable sort of thing to define on <dael> TabAtkins: It's weird and I don't like it, but if it's what we want I'm okay <dael> ericwilligers: What's the need for this? <TabAtkins> .foo:matches(::before, ::after) <dael> TabAtkins: Safari does it for selectors like ^ <dael> TabAtkins: You want to assign a style to multiple psuedo elements. Can't do that with matches right now. That's annoying, I agree <dael> TabAtkins: Reasonable thing. Even bikeshed stylesheet would like to do a selector like this. <fantasai> s/matches/is/ btw ;) <TabAtkins> .foo:matches(::before, .bar) <TabAtkins> ^ invalid <dael> TabAtkins: Another option is we're more limited and you can put psuedo elements in if they're the only thing in the selector. All options have to be pseudo elements <TabAtkins> .foo:matches(::before:hover) is valid <dael> TabAtkins: That would be okay way to deal <plinss> .foo:matches(::before):matches(:hover) ? <TabAtkins> would be valid by my rule I think <dael> fantasai: Thing that's tricky is different pseudo elements can be followed by different things. No need to make first example invalid b/c each branch is valid. If any branch is invalid whole is invalid. <dbaron_> Pseudo elements seem like they might differ in what is allowed after them <dael> fantasai: More restrictive I'm not sure that gains us a whole lot. You'll still need contextual checking. <fantasai> s/checking/checking, even if they're all pseudo-elements/ <dael> TabAtkins: ericwilligers we don't support pseudo elements in matches right now, correct? <dael> ericwilligers: Correct <dbaron_> It seems like you might want to ensure that all branches of the :matches end in the same restriction state <dael> TabAtkins: FF or Edge, how does this sound. Should I close no change and Safari violates spec? Or do we want? <TabAtkins> dbaron_, I agree with that as a good restriction if we go this way <dael> Rossen: Curious to hear from Safari folks. <dael> Rossen: dbaron_ is on IRC [reads] <dbaron_> (where we need to be conservative about what is the same, e.g. before and after OK but not selection) <TabAtkins> :matches(::before, ::spelling-error) would be invalid <dael> TabAtkins: before and after are fine, but before and spelling wouldn't work because allow different things <dael> ericwilligers: Safari uses different selector name. So it doesn't matter too much. <dael> TabAtkins: Not a backwards compat concern. It's what we want to do for the future <dael> TabAtkins: I'm perfectly fine saying close no change <dbaron_> Still have mixed feelings about whether to allow pseudos in v1 <dael> TabAtkins: dbaron_ is unsure. We can relax restriction later <dbaron_> (typing on phone, BTW) <dael> Rossen: smfr said Safari folks can't follow because they're in a meeting <dael> Rossen: Objections to resolving no change? <dael> fantasai: I think deferred <dael> fantasai: Close no change means we don't want to accept. We might accept in future <dael> fantasai: I'd prefer...if we're going to consider in the future we leave it open for selectors 5. If it's a baad idea we close no change. <dael> Rossen: Don't disagree <dael> Rossen: objections to defer to L5? <dael> RESOLVED: Defer this issue to L5 |
(Copied from #4417) In the past I've resisted things like .foo:is(.bar, ::before), because the ::before part is technically changing the subject of the compound selector, something no other selector can do. But this just leaves a functionality gap, since pseudo-elements don't have a combinator dedicated to them to allow matching plainly. Selector syntax is awkwardly designed around pseudo-elements, but we're stuck with it, and should accept that pseudo-elements are part of the compound selector grammar and are allowed to change the subject in a real way. Thus we should make sure that :not()/etc work properly with them too. (There's no reason to use :not() with any of the current pseudos, but ::part(foo):not(::part(bar)) makes sense and is useful.) |
I think |
Rethinking the "nature" of pseudo-elements in terms of selector syntax (#5676), a new way to resolve the contradiction came to my mind...
What if we declare the whitespaces around combinators other than This change seems to make all the examples above unambiguous and retaining their current meaning: e.g. |
It would be weird to allow After some reflection on this, I think a pseudo-element should be allowed in logical combination pseudo-classes when the logical combination pseudo-class is compounded to the same pseudo-element or |
:is()/:matches()
?
https://www.w3.org/TR/2018/WD-selectors-4-20180201/#matches
Safari support
:matches(::before)
The
:matches()
has now been renamed to:is()
The text was updated successfully, but these errors were encountered: