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.

Wrong CSS specificity

See original GitHub issue

Take the following style as an input:

const style = {
  root: {
    "&:hover": {
      "& .icon": {
        color: "red"
      }
    },
    "&.active": {
      "& .icon": {
        color: "blue"
      }
    }
  },
};

Expected behavior: I would expect the following CSS injected into the page:

.root-0-0-1:hover .icon {
  color: red;
}
.root-0-0-1.active .icon {
  color: blue;
}

Describe the bug: The following CSS is injected in the page:

.root-0-0-1.active .icon {
  color: blue;
}
.root-0-0-1:hover .icon {
  color: red;
}

Codesandbox link:

https://codesandbox.io/s/yjyqmo4vqv

Versions (please complete the following information):

  • jss: 10.0.0-alpha.11

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Feb 25, 2019

The workaround:

const style = {
  root: {
    "&:hover": {
      "& .icon": {
        color: "red"
      }
    },
    "&.active": {
-     "& .icon": {
+     "&& .icon": {
        color: "blue"
      }
    }
  },
};

Featured in https://github.com/mui-org/material-ui/pull/14650.

0reactions
vlazhcommented, May 3, 2020

Are there any updates?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specificity - CSS: Cascading Style Sheets - MDN Web Docs
Specificity is an algorithm that calculates the weight that is applied to a given CSS declaration. The weight is determined by the number...
Read more >
How to tackle CSS specificity issues and when to use the ...
If the CSS selectors with conflicting CSS rules have equal specificity, then the browser will use the source order rule and apply the...
Read more >
Specificity Error - CSS - Stack Overflow
So when calculating the specificity of some CSS code I came across with something I find contradictory. According to the "formula" (inline >...
Read more >
Specifics on CSS Specificity
The best way to explain it is to start with an example of where specificity gets confusing and perhaps doesn't behave like you...
Read more >
Importance of CSS Specificity and its best practices
CSS selector with more specificity in the list of selectors, the more likely it will be applied on the element. It's always bad...
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