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.

Add "How can I override styles with higher specificity?" to FAQ

See original GitHub issue

Since this question comes up almost every day in the main repo, we should add a FAQ entry to the website.

Based on this question and answer we should add a note about the &&& workaround and why it works to the FAQ.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

37reactions
morajabicommented, Dec 19, 2017

The ampersand solution is for overriding styles applied with former classNames or styled applied from the parent and some other cases. It’s not meant to be used for overriding inline styles.

/* css */
.header {
  background: #453434; /* overrided */
}
// JSX
<Div className="header sc-wS45d" />

const Div = styled.div`
  && {
    background: white; /* applied */
  }
`
18reactions
mxstbrcommented, Jan 7, 2019

You can use as many & as you want, the more you use the higher the specificity will be!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specificity - CSS: Cascading Style Sheets - MDN Web Docs
The only way to override inline styles is by using !important . Many JavaScript frameworks and libraries add inline styles. Using !important ...
Read more >
How to override styles with higher specificity - Stack Overflow
I need to override some class in my div. So my structure looks like this: How Can I achieve this with higher specificity...
Read more >
How to Override CSS Styles - W3docs
How CSS overriding works, what is the cascading order and inheritance, what are the priorities and some tricks to override them.
Read more >
Strategies for Keeping CSS Specificity Low
A rather forceful way to handle an override is use an existing wrapping element over the area you need to apply style overrides...
Read more >
Importance of CSS Specificity and its best practices
Selectors used inside pseudo classes like :not() with highest specificity will be the specificity. Child or sibling selectors ( >, ~, + )...
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