Bootstrap 4卡座,具有基于视口的列数 [英] Bootstrap 4 card-deck with number of columns based on viewport
问题描述
我正在尝试在引导程序4中实现卡片组功能,以使我所有的卡片都具有相同的高度.
I'm trying to implement the card-deck feature in bootstrap 4 to make all of my cards the same height.
引导程序提供的示例显示了4张漂亮的卡片,但是无论视口如何,它都是4张卡片.在此处中查看.
The examples that bootstrap provides show 4 nice cards, but it's 4 cards on the row, no matter the viewport. See the codeply here.
这对我来说没有意义,因为我想,您希望将卡的最小尺寸缩小到最小,以使内容仍然看起来不错.
This doesn't make sense to me since, I would assume, that you'd want a minimum size for your card to shrink to in order for your content to still look good.
然后我尝试添加一些视口类以打破屏幕尺寸,但是一旦添加了该div,卡片组将不再适用,因此不会使卡片的高度相等.
I then tried adding in some viewport classes to break on screen sizes, but as soon as that div gets added, the card-deck doesn't apply anymore, thus not making the cards equal height.
我怎样才能做到这一点?这是缺少的功能,将在完整版的Bootstrap 4中解决吗?
How can I get this accomplished? Is this a missing feature that will be addressed in the full release of Bootstrap 4?
这是小提琴: https://jsfiddle.net/crrm5q9m/
<div class="card-deck-wrapper">
<div class="card-deck">
<div class="card card-inverse card-success text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>It's really good news that the new Bootstrap 4 now has support for CSS 3 flexbox.</p>
<footer>Makes flexible layouts <cite title="Source Title">Faster</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-danger text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>The Bootstrap 3.x element that was called "Panel" before, is now called a "Card".</p>
<footer>All of this makes more <cite title="Source Title">Sense</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-warning text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>There are also some interesting new text classes for uppercase and capitalize.</p>
<footer>These handy utilities make it <cite title="Source Title">Easy</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-info text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>If you want to use cool icons in Bootstrap 4, you'll have to find your own such as Font Awesome or Ionicons.</p>
<footer>The Glyphicons are not <cite title="Source Title">Included</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-success text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>It's really good news that the new Bootstrap 4 now has support for CSS 3 flexbox.</p>
<footer>Makes flexible layouts <cite title="Source Title">Faster</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-danger text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>The Bootstrap 3.x element that was called "Panel" before, is now called a "Card".</p>
<footer>All of this makes more <cite title="Source Title">Sense</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-warning text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>There are also some interesting new text classes for uppercase and capitalize.</p>
<footer>These handy utilities make it <cite title="Source Title">Easy</cite></footer>
</blockquote>
</div>
</div>
<div class="card card-inverse card-info text-center col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-1">
<div class="card-block">
<blockquote class="card-blockquote">
<p>If you want to use cool icons in Bootstrap 4, you'll have to find your own such as Font Awesome or Ionicons.</p>
<footer>The Glyphicons are not <cite title="Source Title">Included</cite></footer>
</blockquote>
</div>
</div>
</div>
</div>
推荐答案
已更新2018年
Updated 2018
如果您需要 响应式卡片组 ,使用可见性实用程序强制在不同视口宽度(断点)上每隔X列换行...
If you want a responsive card-deck, use the visibility utils to force a wrap every X columns on different viewport width(breakpoints)...
Bootstrap 4响应式卡片组 (v 4.1 )
Bootstrap 4 alpha 2的原始答案
Original answer for Bootstrap 4 alpha 2:
您可以使用网格col-*-*
来获得不同的宽度(而不是卡片组),然后使用flexbox将等高线设置为相等的高度.
You can use the grid col-*-*
to get the different widths (instead of card-deck) and then set equal height to the cols using flexbox.
.row > div[class*='col-'] {
display: flex;
flex:1 0 auto;
}
http://codeply.com/go/O0KdSG2YX2 (alpha 2)
问题在于没有启用card-deck
的flexbox会使用table-cell
,这使得控制宽度变得非常困难.从Bootstrap 4 Alpha 6开始,flexbox是默认设置,因此flexbox不需要其他CSS,并且 h-100
类可用于使卡片全高:
The problem is that w/o flexbox enabled the card-deck
uses table-cell
where it becomes very hard to control the width. As of Bootstrap 4 Alpha 6, flexbox is default so the additional CSS is not required for flexbox, and the h-100
class can be used to make the cards full height: http://www.codeply.com/go/gnOzxd4Spk
相关问题: Bootstrap 4-卡片列中的响应卡
这篇关于Bootstrap 4卡座,具有基于视口的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!