【发布时间】:2021-04-24 04:06:11
【问题描述】:
我在一个 Grid 容器中有四列,每列的结构如下:
<Grid item>
<Typography>Big Title 1</Typography>
<Card className={classes.stretchMe}>
<CardContent>
Content
</CardContent>
</Card>
</Grid>
我希望带有 stretchMe 类的 Card 拉伸到父 Grid 项的底部,但是因为每个 Card 上面都有一个 Typography 组件,它会拉伸到父 div 的高度之外。
如何让所有卡片拉伸到父 Grid 项目的底部而不进一步(即减去排版的高度)?
下面是稍微复杂一点的代码:
import React from 'react';
const useStyles = makeStyles(theme => ({
divider: {
borderBottom: `1px solid ${theme.palette.divider}`,
},
stretchMe: {
height: '100%',
},
}));
const Cards= () => {
const classes = useStyles();
return (
<Grid container item xs={12} spacing={3} justify="space-between" alignItems="stretch">
<Grid item xl={2} lg={2} md={6} xs={12} >
<Typography variant="h4" >
Big Title 1
</Typography>
<Card className={classes.stretchMe}>
<CardContent className={classes.divider}>
<Typography variant="h6">Little Title 1</Typography>
<Avatar />
</CardContent>
<CardContent className={classes.divider}>
<Typography variant="h6">Little Title 2</Typography>
<Typography variant="h4">Content</Typography>
</CardContent>
<CardContent className={classes.divider}>
<Grid container>
<Grid item xs={6}>
<Typography variant="h6">Little Title 3</Typography>
<Typography variant="h4">Content</Typography>
</Grid>
<Grid item xs={6}>
<Typography variant="h6">Little Title 4</Typography>
<Typography variant="h4">Content</Typography>
</Grid>
</Grid>
</CardContent>
</Card>
</Grid>
<Grid item xl={4} lg={4} md={6} xs={12} >
<Typography variant="h4" >
Big Title 2
</Typography>
<Card className="classes.stretchMe">
<CardContent>Content</CardContent>
</Card>
</Grid>
<Grid item xl={3} lg={3} md={6} xs={12} >
<Typography variant="h4" >
Big Title 3
</Typography>
<Card className="classes.stretchMe">
<CardContent>Content</CardContent>
</Card>
</Grid>
<Grid item xl={3} lg={3} md={6} xs={12}>
<Typography variant="h4">
Big Title 4
</Typography>
<Card className="classes.stretchMe">
<CardContent className={classes.divider}>
<div className={classes.teamProfile}>
<Avatar/>
</div>
<div className={classes.teamProfile}>
<Avatar/>
</div>
<div className={classes.teamProfile}>
<Avatar/>
</div>
<div className={classes.teamProfile}>
<Avatar/>
</div>
</CardContent>
</Card>
</Grid>
</Grid>
);
};
export default Cards;
非常感谢,
凯蒂
编辑
这是所需的输出:
我的怀疑是大头衔正在压低卡牌?
【问题讨论】:
-
使用
spacing={0}属性删除间距有帮助吗? -
请您上传所需的输出图像吗?
-
嗨 roa - 我已尝试多次添加图像(希望与我的原始帖子一起添加),但似乎有一个错误,并且出现了完全错误的图像!还有其他想法吗?我在一家屏蔽大多数网站的公司工作 - grrrr!
-
@FranAcuna - 您的意思是向 Grid 容器添加间距={0} 吗?我已经尝试过了,不幸的是它没有帮助,但如果我误解了你的建议,请告诉我。谢谢!
-
@roa - 我已经能够在这里放一张图片:imgur.com/a/G7ruSVH希望这会有所帮助!
标签: css reactjs material-ui