html - 使用 Flex-box 为 Material-UI 制作两个相同高度的网格元素

标签 html css reactjs redux material-ui

我有两个网格元素,我想通过使用 flex 使它们具有相同的高度,但是似乎没有任何效果。我相信我现在可以正确使用 Material UI 中的 Grid 元素。我也尝试过使用高度和宽度属性。

  <Paper elevation={10} style={{padding:'1.5em'}}>

      <Grid container direction='row' spacing={2} style={{display:'flex'}}>

          <Grid item style={{height:'100%', width:'50%'}}>
          </Grid>

          <Grid item style={{height:'100%', width:'50%'}}>
          </Grid>

      </Grid>

  </Paper>

最佳答案

在 Material UI 中,您可以在容器 Grid 上使用 alignItems="stretch",如下面的代码所示:

<Paper elevation={10} style={{padding:'1.5em'}}>
    <Grid container direction='row' spacing={2} alignItems="stretch">

        <Grid item style={{height:'100%', width:'50%'}}>
        </Grid>

        <Grid item style={{height:'100%', width:'50%'}}>
        </Grid>

    </Grid>
</Paper>

而且你不需要设置 style={{display:'flex'}} 因为网格样式也设置了它。

References:

关于html - 使用 Flex-box 为 Material-UI 制作两个相同高度的网格元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57729989/

相关文章:

html - 转换伪元素和父元素时 z-index 不起作用

jquery - Twitter bootstrap - 为选项卡式导航添加动画/过渡效果

javascript - 如何在React中实现Jquery?

php - 如何让图片加载更快?

javascript - 无法将数据推送到 Firebase onclick

jquery - 我已经更改了我的 a :link color with jQuery. 现在我的 a:hover 不起作用

css - 是否可以在 css 继承中的输入之前设置一个 after 伪元素?

javascript - 尝试让按钮在点击触发渲染后保持突出显示

javascript - React Redux 更新项数量(不止一个增量)

html - 创建下拉菜单