Re: [csswg-drafts] [selectors] Functional pseudo-class like :matches() with 0 specificity

@leaverou,

The problem is not with nested :is(). It is that having zero specificity inside the function just seems too drastic to me. The problem you described is that it it increases the specificity of the whole complex selector to such a degree that it makes it harder to override, or that it itself overrides things you don’t want it to. I think that problem can be overcome by just extending the existing specificity rules, so that the specificity inside the function doesn’t **significantly** influence selecting, except to break ties in specificity outside the function (just as class selectors don’t matter for specificity except to break ties in ID selectors). 

So, the old specificity rules is (roughly) that when there is a tie in ID selectors, you look at class selectors. If that is a tie, you look at type selectors. I would add to that, so that if type selectors are tied, then look at ID selectors inside the `:matches()`. If that is still a tie, look at class  selectors inside the `:matches()`. If those tie, then look at type selectors inside the `:matches()`. If those are tied, then look at ID selectors inside the embedded `:matches()`. And so on. 

This allows you to write selectors that are as weak as you like compared to existing selectors, solving your originally stated problems. And inside the functions, you still get the great and important benefits of specificity-based cascading. 

This would allow authors to write rules that don’t override things they don’t want to override, and would allow library authors to write rules that were easy for others to override, but without submitting to the tyranny of rule order. 

And you could write many rules, with extremely low specificity, without worrying about something like `* { max-height: 1000in)` (a rule designed to prevent Android from randomly messing up font sizes) from accidentally overriding all the `max-height` values inside your `:is()`or `matches()` functions. 

PS for my scheme to work, the `:is()`or `:matches()` pseudoclass would also not add its own pseudoclass specificity to the equation. Only the selectors inside it would work as I’ve described. 

-- 
GitHub Notification of comment by bradkemper
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1170#issuecomment-333607961 using your GitHub account

Received on Monday, 2 October 2017 17:39:23 UTC