I am trying to use some CSS-in-JS classes from this answer with a material UI component in my React project. I need to override the CSS coming from Bootstrap so I want to use the !important modifier, I've only used this in .css files before and I'm unsure how to do it in CSS-in-JS. My styles object to be passed into the Material-UI withStyles
function looks like the following, how do I add !important to the fontSize attribute? I've tried 30 !important
and a few other things but nothing seems to work.
Thanks
const styles = {
labelRoot: {
fontSize: 30
}
}
important means that “this is important”, ignore all the subsequent rules,apply ! important rule. The ! important keyword must be placed at the end of the line, immediately before the semicolon.
To set a CSS inline style as an ! important one in javascript, you have to use the element. setAttribute() method.
JSS is an authoring tool for CSS which allows you to use JavaScript to describe styles in a declarative, conflict-free and reusable way. It can compile in the browser, server-side or at build time in Node. JSS is framework agnostic. It consists of multiple packages: the core, plugins, framework integrations and others.
You shouldn't need to do this as Adrian points out, but if you absolutely need to do it you can set it to a string:
const styles = {
labelRoot: {
fontSize: '30px !important',
},
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With