问题
In this question I asked how to override a css property of a material-ui component and was provided a nice example. However, when trying to set the height of the Toolbar component I found I could not override the css due to an over arching @media specification. The following MuiTheme spec was my approach:
const theme = createMuiTheme({
overrides: {
MuiToolbar: {
regular: {
height: "32px",
minHeight: "32px"
}
},
}
});
Here is a visual of the css being over-ridden:
If I introduce a hack and add !important to the minHeight it works. A codesandbox showing this is here: https://codesandbox.io/s/4xmr2j2ny9
What is the proper way to overide an @media spec using MuiTheme?
回答1:
You have to add it like below. The media query statement should be enclosed in single quotes.
MuiToolbar: {
regular: {
backgroundColor: "#ffff00",
color: "#000000",
height: "32px",
minHeight: "32px",
'@media (min-width: 600px)': {
minHeight: "48px"
}
},
Please find the codesandox - https://codesandbox.io/s/q8joyrrrwj
回答2:
MuiThemeProvider is optional for v1.x material-ui and We use the higher-order component created by withStyles to inject an array of styles into the DOM as CSS, Here is working example without changing @media annotation:
https://codesandbox.io/s/7klzx84z71
来源:https://stackoverflow.com/questions/52043271/how-to-over-ride-an-media-css-for-a-material-ui-react-component