Reputation: 86
I need to style *, *:after, *:before
using material ui
, also I need to change the global font-family of the web app. How do i achieve this?
Material-UI Version: 1.0.0-beta.5
React Version: 15.4.1
Upvotes: 2
Views: 6240
Reputation: 5529
For the longest time this was one of those hidden options in Material-UI, but now the easiest way to style any element in the DOM is to use the @global class provided by jss-plugin-global:
const GlobalCss = withStyles({
"@global": {
"html, body": {
margin: 0,
padding: 0
},
".App": {
backgroundColor: "blue",
fontFamily: "sans-serif",
textAlign: "center"
}
}
})(() => null);
Here's a CodeSandbox project as an example, using this method replacing the usual css file.
This feature is referenced here in the docs
Update: MUI v5 has a dedicated component for global styles, but works the same way:
import { GlobalStyles } from '@mui/material'
...
const globalStyle = {
a: {
textDecoration: 'none'
}
}
return (
<>
<GlobalStyles styles={globalStyle} />
<App />
</>
)
}
Upvotes: 7
Reputation: 526
fontFamily is a property of theme. You need to pass down the propertys with a "MuiThemeProvider" wrapper.
const theme = createMuiTheme({
palette : {
primary: {
light: '#fff8e1',
main: '#fff8e1',
dark: '#fff8e1',
},
},
typography: {
useNextVariants: true,
fontFamily : 'Poppins',
fontSize : 12,
},
});
<MuiThemeProvider theme={theme}>
<CssBaseline />
<React.Fragment>
<Typography variant='h4'>
</Typography>
</React.Fragment>
</MuiThemeProvider>
Upvotes: 1
Reputation: 847
index.html
or maybe other name.css link
links to the file of step1 in that html file as normal html file do.Upvotes: 1