【发布时间】:2021-12-24 00:05:22
【问题描述】:
我在排列一些 React Bootstrap 卡时遇到了一些问题,我可以将它们水平对齐的唯一方法是将它们都放在一个 div 中,但是如果我以这种方式运行代码,我需要为每张卡使用一个组件,它最终会出错
基本上,每次我添加一张卡片时,它都会垂直对齐,而不是水平对齐。
HostingCard.tsx
import { Card, Button } from "react-bootstrap";
import "./App.css";
export default function HostingCard() {
return (
<div className="main">
<Card style={{ width: "18rem" }}>
<Card.Img variant="top" src="https://picsum.photos/200" />
<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>
);
}
App.tsx
import React from "react";
import "./App.css";
import Header from "./Header";
import HostingCard from "./HostingCard";
function App() {
return (
<div className="App">
<Header />
<h1 style={{ padding: "1rem" }}>Hospedagens</h1>
<HostingCard />
<HostingCard />
</div>
);
}
App.css
.main {
display: flex;
flex-direction: row;
margin: 0.1rem;
padding: 1rem;
}
【问题讨论】:
-
通常你会在你的应用程序组件中构建一个引导网格并循环遍历你的卡片,每个卡片都有一个列。您的标记中不会有一堆单独的组件。
标签: css reactjs react-bootstrap