css - 在 Grid item Material UI 中将图像对齐到中心

标签 css reactjs material-ui

我正在使用来自 Material UIGrid .我不知道为什么网格元素中的图像向左对齐而不是向中心对齐。

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

同样在 Typography 中,我必须使用 textAlign 才能居中,但如何对齐图像?

最佳答案

尝试为包裹图像的网格提供 container 属性,然后通过添加 justify="center" 和/或 alignItems="使图像居中中心”到这个容器。

关于css - 在 Grid item Material UI 中将图像对齐到中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60079894/

相关文章:

react-native - 带有 React Native 的 Material-ui

PHPmailer 破坏 HTML 正文消息。 (漏洞?)

css - Div 碰撞和高度 : auto

javascript - 当工具提示出现在 slider handle 上时,在控制台中执行 Javascript 时强制回流

javascript - 在 React 中处理复杂的数据结构

javascript - 从 React MaterialUI RadioButtonGroup 获取值和 id

reactjs - 无法覆盖 Mui 选择的背景颜色

html - 包括粗体字体不起作用

javascript - 创建从右到左的屏幕外子菜单导航

javascript - 与嵌套组件共享上下文,未定义获取 UserContext