Using createMuiTheme to override default styles on div's, p's, body

后端 未结 1 1337
粉色の甜心
粉色の甜心 2020-12-22 02:09

This is perhaps a simple Material UI Theme Customization question.

What I want to do is to override the default styling on (and other commo

相关标签:
1条回答
  • 2020-12-22 02:49

    Here is an example of overriding this aspect of CssBaseline:

    import PropTypes from "prop-types";
    import { withStyles } from "@material-ui/core/styles";
    
    const styles = theme => ({
      "@global": {
        body: {
          ...theme.typography.body1
        }
      }
    });
    
    function MyCssBaseline() {
      return null;
    }
    
    MyCssBaseline.propTypes = {
      classes: PropTypes.object.isRequired
    };
    
    export default withStyles(styles)(MyCssBaseline);
    
    
    import React from "react";
    import ReactDOM from "react-dom";
    import CssBaseline from "@material-ui/core/CssBaseline";
    import MyCssBaseline from "./MyCssBaseline";
    
    function App() {
      return (
        <>
          <CssBaseline />
          <MyCssBaseline />
          <span>
            Here is some text in the body that is getting the body1 styling due to
            MyCssBaseline.
          </span>
        </>
      );
    }
    ReactDOM.render(<App />, document.querySelector("#root"));
    
    

    Reference: https://material-ui.com/styles/advanced/#global-css

    0 讨论(0)
提交回复
热议问题