将图像对准网格项目Material UI的中心

问题描述 投票:0回答:2

我正在使用Grid中的Material UI。我不知道为什么Grid项内的图像向左对齐而不是向中心对齐。

    <Grid container direction="row" justify="center" alignItems="center">
      <Grid item xs={6}>
        <Grid container direction="row" justify="center" alignItems="center" alignContent="center" style={{minHeight:"200px"}} >
            <Grid item xs={12}>
              <Typography style={{color:'white', textAlign:'center', fontSize:'2rem'}}>{name}</Typography>
            </Grid>
            <Grid item xs={6}>
              <a href={github} target="_blank">
                <img src={githubIcon} width="32px" height="32px" color="white"/>
              </a>
            </Grid>
        </Grid>
      </Grid>
    </Grid>

同样在版式内部,我必须使用textAlign居中,但是如何对齐图像?

css reactjs material-ui
2个回答
1
投票

尝试给包装图像的网格提供container属性,然后通过向该容器中添加justify="center"和/或alignItems="center"来使图像居中。


0
投票

将此代码用于您的网格标签。

alignContent ='flex-start'alignItems ='flex-start'justify ='flex-start'

我从材料ui文档Material UI/Grid中获得了此>

© www.soinside.com 2019 - 2024. All rights reserved.