reactjs - .map 堆叠卡片而不是并排放置
问题描述
我试图让投资组合页面的卡片在更大的屏幕上并排放置,然后在断点处堆叠,无法让它工作。我正在使用材质ui。我已经多次更改代码,这就是它现在的位置。
return (
<>
<Navbar />
<Box component='div' className={classes.portfolioContainer}>
{projectInfo.map((lsItem, key) => (
<Grid container
justify='center'
key={key}
xs={10}
sm={4}
md={5}
>
<Card className={classes.cardContainer}>
<CardActionArea>
<CardMedia
component='img'
alt={lsItem.projectAltImg}
height='280'
image={lsItem.projectImg}
/>
<CardContent className={classes.textContainer}>
<Typography gutterBottom variant='h5' className={classes.textColor}>
{lsItem.projectTitle}
</Typography>
<Typography variant='body2' color='textSecondary' component='p' className={classes.textColor}>
{lsItem.ProjectDescription}
</Typography>
</CardContent>
<CardActions style={{ display: 'flex', justifyContent: 'center', background: '#304D6D' }}>
<IconButton
size='small'
className={classes.buttonContainer}
style={{ background: '#69DC9E' }}
href={lsItem.ProjectGitHub} target='_blank'
>
<GitHub style={{ color: '#BA5A31' }} />
</IconButton>
<IconButton
size='small'
className={classes.buttonContainer}
style={{ background: '#69DC9E' }}
href={lsItem.ProjectLiveSite} target='_blank'
>
<Language style={{ color: '#BA5A31' }} />
</IconButton>
</CardActions>
</CardActionArea>
</Card>
</Grid>
))}
</Box>
</>
)
解决方案
您没有Grid
正确使用该组件。我建议你看看官方文档。
简而言之,这就是它应该如何工作
<Grid container>
{projectInfo.map((lsItem, key) => (
<Grid item>
<Card />
</Grid>
))}
</Grid>
推荐阅读
- python - Python:如何在 RGB 图像上实现二进制过滤器?(算法)
- python - Pandas 通过 groupby 日期的总和对由 datetimeindex 索引的列进行归一化
- mysql - 带有 MySQL 的 Raspbian Spin Docker 容器
- python - 在只包含常量的文件中不使用类的优点/缺点?
- javascript - 如何从节点控制台调用异步方法?
- swift - 有没有更好的方法来构建许多不同的 URL?
- xml - 在 VS 2015 片段中添加多次 $selected$
- python - 尝试从多个帧创建视频
- zlib - 放气的 zlib 对象有多大?
- xcode - xcode 10,unity,vuforia Command CodeSign 失败,退出代码为非零