我想用Bootstrap卡制作一个3列2行的网格,但网格不起作用。所有的牌都居中,一张接一张。请帮我解决这个问题。
服务.jsx
const Service =() =>{
return(
<div>
<div className="my-5">
<h1 className="text-center">Our Services</h1>
</div>
<div className="container-fluid mb-5">
<div className="row">
<div className="col-10 mx-auto">
<div className="row gy-3">
{Sdata.map((val, ind) => {
return(
<Card key={ind} imgsrc={val.imgsrc} title={val.title} />
)})}
</div>
</div>
</div>
</div>
</div>
);
};
Card.jsx
const Card =(props) =>{
return(
<div>
<div className="col-md-4 col-10 mx-auto">
<div className="card">
<img src={props.imgsrc} className="card-img-top" alt={props.imgsrc} />
<div className="card-body">
<h5 className="card-title font-weight-bold">{props.title}</h5>
<p className="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<NavLink to="#" className="btn btn-primary">Go somewhere</NavLink>
</div>
</div>
</div>
</div>
);
};
"所有的牌都是居中的,一张接着一张;。
列由外部div
包装。列必须直接位于父级.row
中。拆下外部分区
const Card =(props) =>{
return(
<div className="col-md-4 col-10 mx-auto">
<div className="card">
<img src={props.imgsrc} className="card-img-top" alt={props.imgsrc} />
<div className="card-body">
<h5 className="card-title font-weight-bold">{props.title}</h5>
<p className="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<NavLink to="#" className="btn btn-primary">Go somewhere</NavLink>
</div>
</div>
</div>
);
};
Codeply 上的React演示