【问题标题】:How to horizontal center the title in Material-UI AppBar如何在 Material-UI AppBar 中将标题水平居中
【发布时间】:2020-01-09 08:28:40
【问题描述】:

我找不到在 React Material UI AppBar 中居中标题的方法。也许我错过了一些东西。 StackOverflow 上几乎没有其他答案,但这些似乎不是最好的方法。

【问题讨论】:

    标签: javascript reactjs material-design material-ui


    【解决方案1】:

    使用material-ui makeStyles让文字居中:

    import { makeStyles } from '@material-ui/core/styles';
    
    const useStyles = makeStyles(theme => ({
      title: {
        flexGrow: 1,
        textAlign: 'center',
      },
    }));
    

    然后将“标题”样式应用于您的标题组件:

    export default function CenteredTextAppBar() {
      const classes = useStyles();
    
      return (
        <div>
          <AppBar position="static">
            <Toolbar>
              <Typography variant="h6" className={classes.title}>
                Centered Text
              </Typography>
            </Toolbar>
          </AppBar>
        </div>
      );
    }
    

    你可以参考这个CodeSandbox的例子。

    【讨论】:

      猜你喜欢
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 2018-12-02
      • 2018-10-10
      • 1970-01-01
      • 2021-11-11
      相关资源
      最近更新 更多