【发布时间】:2021-09-27 23:55:53
【问题描述】:
我有一排动态放置的 reactstrap 卡片,对于“md”屏幕尺寸及以上(引导),每行将有 3 张卡片,对于较低的它将是 2 张卡片。
这是组件:
<Card
outline
as='a'
style={{ cursor: 'pointer', margin: '1rem' }}
>
<CardImg top width='100%' src={img}' />
<CardBody>
<CardTitle tag='h5'>{this.props.title}</CardTitle>
</CardBody>
</Card>
我的问题是,我只希望中间的卡片在边上有边距(marginLeft: '1rem', marginRight: '1rem')。
由于连续卡片的数量会根据屏幕大小而变化,我不能只说“如果它是 x 的倍数,那么就具有这种风格”。除非我知道屏幕尺寸,否则有没有办法在我的父组件中创建一个道具,我可以将它传递给我的卡片组件,让它知道将边距设置为什么?
谢谢
(欢迎提出更好的建议)
更多代码:
render () {
return (
...
<div className='row' style={{margin:'0rem'}}>
{
disp.map((d, index) => {
return (
<div className='col-md-4 col-6 d-flex'>
<the card component here>
</div
)
...
}
}
</div>
....
【问题讨论】:
-
如果里面有一排多张卡片,如果我没记错,那么你需要在它们之间留出空间,这就是你添加maring的原因。对吗?
-
是的,我想要每张卡片之间的空间,但我不想在整个网格的一侧有额外的边距@decpk
标签: html css reactjs bootstrap-4