在Material UI(MUI)中,要将卡片的页脚与底部对齐,可以使用Card
组件结合Box
组件和CSS Flexbox布局来实现。以下是一个示例代码,展示了如何实现这一效果:
import React from 'react';
import { Card, CardContent, CardActions, Typography, Box } from '@mui/material';
const MyCard = () => {
return (
<Card sx={{ display: 'flex', flexDirection: 'column' }}>
<CardContent>
<Typography variant="h5" component="div">
Card Title
</Typography>
<Typography variant="body2" color="text.secondary">
This is the main content of the card.
</Typography>
</CardContent>
<Box sx={{ flexGrow: 1 }} />
<CardActions>
<Typography variant="body2">Card Footer Content</Typography>
</CardActions>
</Card>
);
};
export default MyCard;
Box
组件的sx
属性设置为{ flexGrow: 1 }
,这使得Box
组件占据剩余的空间,从而将CardActions
推到卡片的底部。这种布局方式适用于需要在卡片中显示主要内容和底部页脚的场景,例如:
通过这种方式,你可以确保卡片的页脚始终与底部对齐,无论卡片内容的长度如何变化。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云