3

I want to override the MuiBox-root style for the whole application.According to the official documentation I need to identify the class:

enter image description here

And among other things I can override it:

enter image description here

But if I proceed this way, it just removes the styling. What am I doing wrong here?

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
assembler
  • 3,098
  • 12
  • 43
  • 84
  • The `createMuiTheme`, as said in the document, "change every single style injected by Material-UI into the DOM". So it will wipe out the old CSS and replace them with your CSS. If you only want to change some property and leave the rest untouched then maybe `makeStyles` is your answer – kunquan Dec 09 '20 at 20:41
  • @kunquan I want to change the padding property only once – assembler Dec 09 '20 at 20:44
  • show the whole of the code – Nikhil S Dec 09 '20 at 20:45
  • Yes you can do that with `makeStyles`. You can see how to use that by go to any component and choose to view the whole code. This method basically allow you to write CSS and won't completely wipe out the default CSS – kunquan Dec 09 '20 at 21:29
  • @kunquan I can not get this working... it keeps rendering the same value – assembler Dec 10 '20 at 15:15
  • @assembler give it a green tick. – Nikhil S Dec 25 '20 at 08:53

3 Answers3

1

This will do:

import { withStyles } from "@material-ui/core/styles";

const styles = {
  root: {
    padding: "10px"
  }
};

function App({ classes }) {
  return <yourelement  className={classes.root}>xyz...<yourelement/>;
}
export default withStyles(styles)(App);
Nikhil S
  • 3,786
  • 4
  • 18
  • 32
0

You can use the sx property on the Box component. For example:

<Box sx={{ padding: "10px" }}>
   <YourChildComponents/>
</Box>
trn450
  • 251
  • 2
  • 8
0

Lets say aim is to override background css field of root background css field. Below are the steps

import { makeStyles } from '@mui/styles';

const useStyles = makeStyles({
  root: {
    background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
  },
});

export default function testFunction() {
  const classes = useStyles();
  return <Button className={classes.root}>Hook</Button>;
}

Hope this will help.

banoth ravinder
  • 1,314
  • 15
  • 18