W3C home > Mailing lists > Public > public-css-archive@w3.org > December 2017

Re: [csswg-drafts] [selectors-4] reconsider specificity rule for :matches()

From: Oriol Brufau via GitHub <sysbot+gh@w3.org>
Date: Sun, 31 Dec 2017 14:06:11 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-354605655-1514729170-sysbot+gh@w3.org>
@SelenIT
> could you please provide an example of this possibility?

If I understand correctly, an example could be

```html
<div id="a"></div>
<div id="b">
  <div id="c"></div>
  <div id="d" class="foo">
    <span id="e">Styles are being assigned to this element</span>
  </div>
</div>
```
```css
:matches(#a, *) + :matches(.foo, *) span
```

An implementation could detect that

1. `#e` matches `span` with specificity (0,0,1).
2. `#d` matches both `.foo` and `*`, so it matches `:matches(.foo, *)` with specificity (0,1,0).
3. `#c` matches `*` but not `#a`, so it matches `:matches(#a, *)` with specificity (0,0,0).

So the whole selector is matched with specificity (0,0,0)+(0,1,0)+(0,0,1) = (0,1,1)

However, there is another way to match the selector:

1. `#e` matches `span` with specificity (0,0,1).
2. `#b` matches `*` but not `.foo`, so it matches `:matches(.foo, *)` with specificity (0,0,0).
3. `#a` matches both `*` `#a` and `*`, so it matches `:matches(#a, *)` with specificity (1,0,0).

So the whole selector is matched with specificity (1,0,0)+(0,0,0)+(0,0,1) = (1,0,1)

It would be bad if different implementations calculated the specificity of `:matches` on different elements, because this could affect the total specificity. `:nth-*` are also affected:

> the specificity of an :nth-child(), :nth-last-child(), :nth-of-type(), or :nth-last-of-type() selector is the specificity of the pseudo class itself (counting as one pseudo-class selector) plus the specificity of its selector list argument (if any)

I see various possible solutions:

 - Properly specify on which elements the pseudo-classes are calculated, e.g. the ones that maximize the total specificity. This might have performance problems.
 - Ignore the selector list argument and let the specificity be (0,1,0) like a normal pseudo-class. `:-moz-any` and `:-webkit-any` seem to behave like this.
 - Remove `:something`/`:is` and define the specificity of `:matches` to be (0,0,0).

-- 
GitHub Notification of comment by Loirooriol
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1027#issuecomment-354605655 using your GitHub account
Received on Sunday, 31 December 2017 14:06:13 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:41:21 UTC