[英]How to get React-bootstrap cards the same size?
I am using React-bootstrap for my app, specifically the Card& CardGroup components.我正在为我的应用程序使用 React-bootstrap,特别是 Card 和 CardGroup 组件。 I want help please with making the cards all the same height.
我需要帮助使卡片高度相同。
JSX component: JSX 组件:
<Card style={{flex: 1}} className="card">
<Card.Img variant="top" src={Weather} />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in
to additional content. This content is a little bit longer.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card style={{flex: 1}} className="card">
<Card.Img variant="top" src={Scheduler} />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>
This card has supporting text below as a natural lead-in to
additional content.{' '}
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card style={{flex: 1}} className="card">
<Card.Img variant="top" src={Quiz} />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in
to additional content. This card has even longer content than the
first to show that equal height action.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
</CardGroup>
)
Related CSS:相关CSS:
.card {
padding: 30px;
margin-top:59px;
}
Here's what it currently looks like enter image description here这是目前的样子在这里输入图片描述
I have tried using max-height and min-height, but it didnt work.我试过使用最大高度和最小高度,但没有用。 I learned react a month ago and thus are trying to get acclimated with it.
我一个月前学会了反应,因此正在努力适应它。 I would truly appreciate help on how to make these cards all the same height/size, regardless of the height of the photos.
无论照片的高度如何,如何使这些卡片的高度/尺寸都相同,我将不胜感激。 Or how to make the photo sizes the same as well.
或者如何使照片尺寸也相同。
Thank you so much太感谢了
Not sure if I understand the desired result, but if the goal is to:不确定我是否理解期望的结果,但如果目标是:
make these cards all the same height/size, regardless of the height of the photos
让这些卡片的高度/尺寸都相同,不管照片的高度如何
It seems that Card.Body
is already taking the remaining space of Card
, and it could be styled to align the text and button to the bottom, making the whole CardGroup
aligned vertically.似乎
Card.Body
已经占用了Card
的剩余空间,并且可以将其样式设置为将文本和按钮对齐到底部,从而使整个CardGroup
垂直对齐。
The below example adds some bootstrap classes for this as a basic solution.下面的示例为此添加了一些引导程序类作为基本解决方案。
Live demo of the simplified example on: stackblitz简化示例的现场演示: stackblitz
Example:例子:
<CardGroup>
<Card className="card d-flex flex-column">
<Card.Img src={Weather} />
<Card.Body className="d-flex flex-column justify-content-end align-items-center">
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in to
additional content. This content is a little bit longer.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card className="card d-flex flex-column">
<Card.Img src={Scheduler} />
<Card.Body className="d-flex flex-column justify-content-end align-items-center">
<Card.Title>Card title</Card.Title>
<Card.Text>
This card has supporting text below as a natural lead-in to additional
content.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
<Card className="card d-flex flex-column">
<Card.Img src={Quiz} />
<Card.Body className="d-flex flex-column justify-content-end align-items-center">
<Card.Title>Card title</Card.Title>
<Card.Text>
This is a wider card with supporting text below as a natural lead-in to
additional content. This card has even longer content than the first to
show that equal height action.
</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
</CardGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.