0

so I'm using Material UI Components on my react-app, for example for a button text, I would like to give it a margin-top and font-weight, however, I'm using CSS Modules, so I cannot just override the default CSS Styles, so I had to use the !important flag, is there a cleaner/better approach to do this and avoid using the better flag? Here's an example of what I'm looking like for a certain component.

enter image description here

I was adviced to use atomic CSS but googling that it seems like they're advising me to use in-line styles and that's something I've been meaning to avoid for future reusability.

TIA

5
  • I'm not aware of Material UI so I don't know if there is a better answer out there, but could you order your stylesheets so that your external stylesheet is last, making it override any other styles. This should hopefully avoid the !important Commented Oct 16, 2019 at 12:51
  • How can I do so? Commented Oct 16, 2019 at 12:53
  • How is the Material UI css referenced? Commented Oct 16, 2019 at 12:56
  • an import in my react app's app.js Commented Oct 16, 2019 at 12:59
  • In the JS?! How so? If that is the case, I dont think my answer will help. Commented Oct 16, 2019 at 13:00

2 Answers 2

1

Got through by setting specific CSS classes, for example for this font weight and margin top, my new CSS looks like

.loginSignUpLink.priority {
    margin-top: 4%;
    font-weight: 1000;
}

and my classname is as follows

className={classNames(styles.loginSignUpLink, styles.priority)}

Sign up to request clarification or add additional context in comments.

Comments

0

Using important in CSS is not a good way. I prefer you please use the parent class or tag to avoid important. One main thing is very important your CSS run last after all CSS files. It is the most important. For example please check the below code.

<div class="test">
   <span class="span"></span>
</div>

Than write down css for span like this

div.test span.span{ ... }

Also, you use more hierarchy to avoid important in css

body div.test span.span{ ... }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.