简体   繁体   English

将图像与网格项目材质 UI 中的中心对齐

[英]Align image to the center in Grid item Material UI

I am using Grid from Material UI .我正在使用Material UI 中的Grid I dont know why image inside Grid item is align to the left and not to the center.我不知道为什么 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>

Also inside Typography I have to use textAlign to be in the center, but how to align an image?同样在 Typography 中,我必须使用textAlign来居中,但是如何对齐图像?

尝试给 Grid 包装图像, container属性,然后通过向此容器添加justify="center"和/或alignItems="center"来使图像alignItems="center"

use this code intoyour grid tag.将此代码用于您的网格标签。

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

i got this from material ui docs Material UI/Grid我从Material UI文档Material UI/Grid 中得到了这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM