Skip to content

[scoping] Selectors in ::slotted don’t affect specificity #2271

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

Closed
surma opened this issue Feb 4, 2018 · 3 comments
Closed

[scoping] Selectors in ::slotted don’t affect specificity #2271

surma opened this issue Feb 4, 2018 · 3 comments

Comments

@surma
Copy link
Member

surma commented Feb 4, 2018

Let’s say I have a custom element <my-elem>, that has the following shadow root markup:

<style>
  /* ... */
  ::slotted(main) {
    background-color: blue;
  }
  ::slotted(*) {
    background-color: red;
  }
</style>
<slot></slot>
<my-elem>
  <div>DIV!</div>
  <main>MAIN!</main>
  <aside>ASIDE!</aside>
</my-elem>

I’d argue most authors would expect <main> to have a blue background color, but it is in fact red. AFACIT, this is currently per spec. Selectors passed to ::slotted() don’t affect specificity. So precedence is defined by order of declaration.

Was this intentional? If so, why? If not, is it changeable?

(Live demo, code)

@emilio
Copy link
Collaborator

emilio commented Feb 4, 2018

This is also related to #1915, and also (loosely) to #2158 / #1027.

Note that the spec as of right now doesn't do any kind of special-casing, so :host and :host-context should also not have any particular specificity rules, but @lilles mentioned there why he thought it's unfortunate.

@Nadya678
Copy link

Nadya678 commented Feb 5, 2018

Workaround

<style>
  /* ... */
  :root ::slotted(main) 
  {
    background-color: blue;
  }
  ::slotted(*) 
  {
    background-color: red;
  }
</style>
<slot></slot>

I think it should work like :not() for specificity calculation.

@tabatkins tabatkins changed the title [selectors] Selectors in ::slotted don’t affect specificity [scoping] Selectors in ::slotted don’t affect specificity Feb 6, 2018
@tabatkins tabatkins added css-scoping-1 Current Work css-pseudo-4 Current Work and removed css-pseudo-4 Current Work labels Feb 6, 2018
@surma
Copy link
Member Author

surma commented Apr 11, 2018

This has been addressed in #1915. Closing this.

@surma surma closed this as completed Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants