Skip to content
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

Improve :root selector to get better specificity #330

Closed
yhatt opened this issue Apr 16, 2022 · 0 comments · Fixed by #333
Closed

Improve :root selector to get better specificity #330

yhatt opened this issue Apr 16, 2022 · 0 comments · Fixed by #333

Comments

@yhatt
Copy link
Member

yhatt commented Apr 16, 2022

#247 has improved the specificity for :root selector, but actually that was not following the correct specificity.

  • section selector has "0-0-1" specificity.
  • Original :root selector has "0-1-0" specificity, win against section.
  • A current replaced selector section:not(a) has "0-0-2" specificty. It will win against the simple section selector, but may lose against the complex selector.

For example, this CSS + HTML document will render text in green.

:root p { /* 0-1-1*/
  color: green;
}

html div p { /* 0-0-3 */
  color: red;
}
<html>
<body>
  <div>
    <p>green</p>
  </div>
</body>
</html>

In Marpit, this Markdown is having exactly same shape of above, but renders text in wrong color red.

<style>
:root p { /* 0-0-3*/
  color: green;
}

section div p { /* 0-0-3 */
  color: red;
}
</style>

<div>

green

</div>

Using :where() selector would be useful to match the specificity to :root (0-1-0).
https://polypane.app/css-specificity-calculator/#selector=%3Awhere(section)%3Anot(%5B%5C20%20root%5D)

:root { /* 0-1-0 */ }
section:not(a) { /* 0-0-2:  */ )
:where(section):not([\20 root]) { /* 0-1-0:  */ )

:not([" root"]) pseudo-class will always match because HTML does not allow U+0020 SPACE in the attribute name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant