【发布时间】:2021-10-19 00:29:39
【问题描述】:
我想将卡片放在网格项目的中心,但它不起作用。 正如我从文档 (https://material-ui.com/components/grid/) 中了解到的那样,我应该使用 justifyContent="center" 但这不起作用,并且在堆栈溢出 (How to center a component in Material-UI and make it responsive?) 的答案之一中,有人使用 justify="center" 代替,所以我也试过了,但是没用。
<Grid container justifyContent="center">
<Grid item xs={12} md={4} >
<Card style={{maxWidth: 345}}>
<CardActionArea>
<CardMedia
style={{height: 140}}
image="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8cHJvZHVjdHxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80"
title="Contemplative Reptile"
/>
<CardContent>
<Typography variant="h5" component="h2">
Lizard
</Typography>
<Typography gutterBottom variant="body2" color="textSecondary" component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000 species, ranging
across all continents except Antarctica
</Typography>
<Typography gutterBottom varient="h5" color="Secondary">
100
</Typography>
</CardContent>
</CardActionArea>
</Card>
</Grid>
<Grid item xs={12} md={4}>
<Card style={{maxWidth: 345}}>
<CardActionArea>
<CardMedia
style={{height: 140}}
image="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8cHJvZHVjdHxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80"
title="Contemplative Reptile"
/>
<CardContent>
<Typography variant="h5" component="h2">
Lizard
</Typography>
<Typography gutterBottom variant="body2" color="textSecondary" component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000 species, ranging
across all continents except Antarctica
</Typography>
<Typography gutterBottom varient="h5" color="Secondary">
100
</Typography>
</CardContent>
</CardActionArea>
</Card>
</Grid>
<Grid item xs={12} md={4}>
<Card style={{maxWidth: 345}}>
<CardActionArea>
<CardMedia
style={{height: 140}}
image="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8cHJvZHVjdHxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80"
title="Contemplative Reptile"
/>
<CardContent>
<Typography variant="h5" component="h2">
Lizard
</Typography>
<Typography gutterBottom variant="body2" color="textSecondary" component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000 species, ranging
across all continents except Antarctica
</Typography>
<Typography gutterBottom varient="h5" color="Secondary">
100
</Typography>
</CardContent>
</CardActionArea>
</Card>
</Grid>
</Grid>
【问题讨论】:
标签: reactjs material-ui grid containers card