简体   繁体   中英

Align image to the center in Grid item Material UI

I am using Grid from Material UI . I dont know why image inside Grid item is align to the left and not to the center.

    <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?

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

use this code intoyour grid tag.

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

i got this from material ui docs Material UI/Grid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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