gpt4 book ai didi

css - Bootstrap 4 垂直居中 - 等高卡片

转载 作者:行者123 更新时间:2023-11-28 09:16:24 25 4
gpt4 key购买 nike

我正在使用 Bootstrap 4 alpha 6,并尝试使用 flexbox 将等高卡片的内容垂直居中。我使用了 h-100 util 类来制作带有列的全高卡片..

问题是我希望每张卡片的内容在中间对齐(垂直居中)。我尝试在行中使用 .align-items-center 类,它可以使卡片居中,但卡片不再等高...

enter image description here

HTML

<div class="container">
<div class="row align-items-center bg-faded">
<div class="col-md-2">
<div class="card card-block h-100">
I have a lot of content that wraps on multiple lines..
</div>
</div>
<div class="col-md-6">
<div class="card card-block h-100">
I have a line of content.<br>
And another line here..
</div>
</div>
<div class="col-md-4">
<div class="card card-block h-100">
I have a little bit.
</div>
</div>
</div>
</div>

Demo of problem

最佳答案

这里有一个更简单的解决方案:

仅使用 justify-content-center 工具类,因为 .card 已经有 flex-direction: column 属性

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<code>normal .row with .card inside .col-*</code>
<h6>Problem is that card content is not centered</h6>
<div class="row bg-faded">
<div class="col-md-2">
<div class="card card-block h-100 justify-content-center align-items-center">
I have a lot of content that wraps on multiple lines..
</div>
</div>
<div class="col-md-6">
<div class="card card-block h-100 justify-content-center align-items-center">
I have a line of content.<br>
And another line here..
</div>
</div>
<div class="col-md-4">
<div class="card card-block h-100 justify-content-center align-items-center">
I have a little bit.
</div>
</div>
</div>
</div>
<hr>
<div class="container">
<code>.align-items-center.row with .card inside .col-</code>
<h6>Problem is that cards are no longer full height</h6>
<div class="row bg-faded">
<div class="col-md-2">
<div class="card card-block h-100 justify-content-center">
I have a lot of content that wraps on multiple lines..
</div>
</div>
<div class="col-md-6">
<div class="card card-block h-100 justify-content-center">
I have a line of content.<br>
And another line here..
</div>
</div>
<div class="col-md-4">
<div class="card card-block h-100 justify-content-center">
I have a little bit.
</div>
</div>
</div>
</div>

关于css - Bootstrap 4 垂直居中 - 等高卡片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42650798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com