question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS specificity issue with :global()

See original GitHub issue

Describe the bug usually, the CSS specificity is id > class > tag. but when using global style syntax, the class is not taking president over the Tag.

To Reproduce svelte REPL

Expected behavior I would expect that in the case of

<p class="class">secret stuff</p>

the following style

<style>
  :global(.class){ 
    /* some style */ 
  } 
</style>

will override styled Tag with

<style>
  p{ 
    /* some style */
  }
</style>

Information about your Svelte project:

  • browser version: any

  • operating system: OS X 10

  • Svelte version: v3.29.0

Severity I think this is kind of severe, but I may be missing some background on this specific use-case

Additional context working on a table component and want to override styles from the outside

<style>
  :global(.td){
    color: red;
  }
}
</style>

<MySuperTableComp data={somedata} />

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
galangelcommented, Oct 8, 2020

@mosheduminer, Amazing, thank you.

1reaction
Conduitrycommented, Oct 5, 2020

I think I’m more inclined to say that this is not a bug, but a gotcha. Scoped styles on p are compiling to p.svelte-123xyz, which has a higher specificity than .class. One way to increase the specificity of .class is to use the selector .:global(.class.class) instead. I don’t think we want Svelte to be doing anything to change the selectors that appear inside :global()s.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specificity - CSS: Cascading Style Sheets - MDN Web Docs
Specificity is the algorithm used by browsers to determine the CSS declaration that is the most relevant to an element, which in turn, ......
Read more >
Strategies for Keeping CSS Specificity Low
Keeping CSS specificity low across all the selectors in your project is a worthy goal. It's generally a sign that things are in...
Read more >
The End of Global CSS - Medium
We've worked around the issues of global scope with a series of naming conventions like OOCSS, SMACSS, BEM and SUIT, each providing a...
Read more >
CSS Specificity: Things You Should Know - Smashing Magazine
Let's take a look at some important issues related to CSS Specificity as well as examples, rules, principles, common solutions, ...
Read more >
Issue with :global() css-module selectors not being pure in ...
[1]: This method doesn't make the styles truly global as the styles are still scoped. The class foo will work only when some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found