javascript - 如何在我的 React 组件中打印出行和列
问题描述
我将 React 与 React Boostrap 一起使用,我试图弄清楚如何将三张卡片放在三列上,并在每次达到三张卡片时添加一个新行。我似乎无法理解如何打印出新的 Row 标签。据我了解,我无法以一种好的方式将条件包裹在 and 标签周围。我怎么能接近这个?
{items &&
items.map((item, index) =>
<Row>
<Col>
<Card style={{ width: '18rem' }}>
<Card.Img variant="top" src={item.logo}/>
<Card.Body>
<Card.Title>Card Title</Card.Title>
<Card.Text>
Some quick example text to build on the card title and make up the bulk of
the card's content.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
</Col>
</Row>
)
}
解决方案
display: 'grid'
使用and可以更快、更干净地完成它 gridTemplateColumns:'1fr 1fr 1fr'
。
你必须将父级设置display
为grid
并grid-template-columns
设置为1fr 1fr 1fr
你将有一个表,每个表都有父级的 1 部分。
您的代码将如下所示:
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr' }} >
{items && items.map((item, index) =>
<Card style={{ width: '18rem' }}>
<Card.Img variant="top" src={item.logo} />
<Card.Body>
<Card.Title>Card Title</Card.Title>
<Card.Text>
Some quick example text to build on the card title and make up the bulk of
the card's content.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
)}
</div>
更多关于网格的信息在这里!
推荐阅读
- php - 在谷歌应用引擎的 laravel 过山车 cms 中使特定文件夹可写
- angular6 - "ng generate application xyz" CLI not woking
- php - 在php中登录成功后如何重定向到另一个页面?
- dialogflow-es - DialogFlow:“添加响应”在 Web 演示中不起作用
- angular - Angular:用于显示树的递归组件
- opencv - 如何获得相机校准矩阵?
- python - Docker 容器在启动时在 requirements.txt 中安装新包
- python - Django - TypeError:“NoneType”类型的对象在进行分页时没有发生 len()
- node.js - 我无法通过 CMD 使用 npm 安装 httpster
- swift - 如何只设置一次导航控制器设置