[英]Make two grid items for Material-UI both same height with Flex-box
我有两个网格项目,我想通过尝试使用flex使其高度相同,但是似乎没有任何效果。 我相信我现在可能在Material UI中正确使用了Grid元素。 我也尝试过使用height和width属性。
<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>
如果在父元素上使用flex,则可以尝试设置align-items: stretch
在父元素上也align-items: stretch
。 这应该将该元素的所有子元素拉伸到相同的高度。 例如
.container {
display: flex;
align-items: stretch;
}
在材料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'}}
因为网格样式也可以设置它。
参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.