【发布时间】:2021-06-28 14:36:12
【问题描述】:
我也尝试使用类似的网格在映射循环内显示卡片。
<div className={classes.root}>
{data.tableData.childRows.map((el: any, idx: number) => {
return (
<Grid
container
spacing={2}
direction="row"
justify="flex-start"
alignItems="flex-start"
>
<Grid item xs={3}>
<Card className={classes.root} variant="outlined">
<CardContent>
<Typography color="textPrimary" gutterBottom>
Name: {data.name}
</Typography>
<Typography color="textPrimary">
Email: {data.email}
</Typography>
<Typography color="textPrimary">
Gateway: {el.gateway}
</Typography>
<Typography color="textPrimary">
ID: {el.id}
</Typography>
<Typography color="textPrimary">
Created: {el.creationDate}
</Typography>
</CardContent>
<CardActions>
<Button
size="small"
onClick={() => {
alert("button clicked" + data.email);
}}
>
Action
</Button>
</CardActions>
</Card>
</Grid>
</Grid>
);
})}
</div>
我的makeStyle是这样的
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
padding: theme.spacing(2),
},
}));
const classes = useStyles();
但卡片显示为一张在另一张的顶部,并与左侧对齐。 如何将等距的卡片连续显示?
【问题讨论】:
标签: css reactjs flexbox material-ui