【问题标题】:Applying styles to materialui component将样式应用于材质 ui 组件
【发布时间】:2020-08-30 15:26:12
【问题描述】:

`

import React, { Component } from 'react';
import Header from './Components/UI/header';
import { Box, Paper } from '@material-ui/core';
import { ThemeProvider, withStyles} from '@material-ui/core/styles';


const styles = () => ({
  overrides: {
    'MuiPaper-root': {
      root: {
        backgroundColor: '#345f',
      }

    }
  }
});





export class App extends Component {
  render() {
    const classes = this.props;
    return(<ThemeProvider theme={theme}>
      <Paper classes={classes.overrides}>
          <Box display="flex" justifyContent="center" alignItems="center" height={1}>
            <Header />
          </Box>
      </Paper>
    </ThemeProvider>);
  }
}


export default withStyles(styles)(App);

`project img link

我正在尝试对 paper api 组件应用不同的背景颜色。当我运行代码时,它会生成相同的基本样式。

【问题讨论】:

  • 请不要将代码发布为图片。
  • 不客气。

标签: javascript reactjs material-ui


【解决方案1】:

您无需担心 MUI 生成的样式或根目录。这将设置您本地的&lt;Paper /&gt; 组件的背景

const styles = () => ({
  overrides: {
     backgroundColor: '#345f',
  }
}); 

【讨论】:

    猜你喜欢
    • 2020-09-13
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 2022-07-19
    • 2021-12-10
    • 2020-09-21
    相关资源
    最近更新 更多