Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add !important to a CSS-in-JS (JSS) class property?

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
  }
}
like image 969
intA Avatar asked Feb 05 '19 01:02

intA


People also ask

How do you use important in style tag?

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.

How do you make important in JavaScript?

To set a CSS inline style as an ! important one in javascript, you have to use the element. setAttribute() method.

What is JSS in CSS?

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.


1 Answers

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',
  },
};
like image 113
Danny Delott Avatar answered Sep 19 '22 10:09

Danny Delott