【发布时间】:2021-05-29 05:28:34
【问题描述】:
我创建了一个应用来映射页面上的所有卡片组件。但是组件是垂直显示的。我需要每行显示 3 个组件。我怎么能这样表现出来?这是我的代码。
const[item, setItem] = useState([]);
function addItem(newItem){ //This addItem Part is working.
setItem(prevItems =>{
return [...prevItems, newItem]
});
}
return(<div className="container">
<div className="row">
<div className="col-lg-4" style={{cursor: "pointer"}}>
<AddCard />
</div>
<div style={{cursor: "pointer"}}>
{item.map((items, index)=>{
return(
<div className="col-lg-4" >
<ItemCard
key={index}
id={index}
title={items.title}
description={items.description}
/>
</div>
)
})}
</div>
</div>)
【问题讨论】:
-
这听起来像是一个关于 CSS 的问题,而不是关于 React 的问题。我在你的代码中看到了一些类,比如
col-lg-4——我假设这来自你正在使用的一些 CSS 框架。我们可能有必要知道是哪个框架——例如,Bootstrap 或 Semantic UI。 -
我正在使用 react-boostrap
标签: javascript css reactjs react-hooks react-bootstrap