[英]MUI v5 Grid - space grid items evenly (justifyContent: space-evenly)
我想實現一個最小高度為 500px 的框,並在該框內垂直居中放置三張卡片。 卡片應均勻分布,但justifyContent="space-evenly"
根本不影響。
我正在使用 MUI v5 ( "@mui/material": "5.10.4"
)。
我究竟做錯了什么?
<Grid
container
spacing={0}
direction="column"
alignItems="center"
justifyContent="center"
sx={{
minHeight: 500,
backgroundColor: '#f1f2f3',
'&:hover': {
backgroundColor: '#ffffff',
},
}}
>
<Grid item xs={12}>
<Grid container direction="row" justifyContent="space-evenly" alignItems="center" sx={{pt:10, pb:10}}>
<Grid item>
<Card sx={{
width: 300,
height: 400,
backgroundColor: "#030814",
}}>
</Card>
</Grid>
<Grid item>
<Card sx={{
width: 300,
height: 400,
backgroundColor: "#030814",
}}>
</Card>
</Grid>
<Grid item>
<Card sx={{
width: 300,
height: 400,
backgroundColor: "#030814",
}}>
</Card>
</Grid>
</Grid>
</Grid>
</Grid>
謝謝!
似乎在您的父Grid
容器中direction="column"
導致了問題。 您需要將其設置為direction="row"
或將其刪除。
這是工作代碼和框
<Grid
container
spacing={0}
// direction="column" // This is causing the issue
alignItems="center"
justifyContent="center"
sx={{
minHeight: 500,
backgroundColor: '#f1f2f3',
'&:hover': {
backgroundColor: '#ffffff',
},
}}
>
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.