gpt4 book ai didi

html - 循环中的等高 Bootstrap 框

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:23 25 4
gpt4 key购买 nike

每当我遇到这个问题时,我都会很挣扎,而且我还没有找到让我的生活更轻松的解决方案。我的布局很简单,并排放置 14 个盒子。我在盒子上使用 col-sm-12 类(我的 Bootstrap 配置为有 24 列)。但是盒子里的内容各不相同,所以它们的高度不相等,更大的盒子紧接着“推”盒子。非常简单的解决方案是在每两个框之后使用一行,但问题是,框是由循环生成的!我可以设置一个 min-height 但这在移动设备上看起来不太好(横向空间太大)。我不确定浏览器是否支持 flexbox

还有其他我可以使用的技巧吗?

HTML

<div class="row">
<div class=" col-xs-24 col-sm-12 col-md-12 blocks"><!--the loop starts from here-->
<div class="row">
<div class="col-sm-8"> some content</div>
<div class="col-sm-16">some more content that changes height. you can put some lorem isum in here. </div>
</div>
<!--my loop, aka, blocks, end here-->
</div>
</div>

最佳答案

flex 是您的解决方案,真的 - 当涉及到等高的列/框时:flex 它 - 让浏览器进行计算和所有“繁重的工作”。

.wrapper {
display: block;
max-width: 500px;
margin: 30px auto;
}

.flex-row {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.flex-row div[class*="col-sm"] {
background: #ddd;
padding: 10px;
box-sizing: border-box;
flex: 0 1 45%;
}
<head>
<link rel="stylesheet prefetch" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<div class="wrapper">
<div class=" col-xs-24 col-sm-12 col-md-12 blocks"><!--the loop starts from here-->
<div class="row flex-row">
<div class="col-sm-8"> some content</div>
<div class="col-sm-16">some more content that changes height. you can put some lorem isum in here. </div>
</div>
<!--my loop, aka, blocks, end here-->
</div>
</div>

CodePen Example

支持

就浏览器支持而言,flex 现在通常得到很好的支持 - 除了 Safari 浏览器 - 尽管 caniuse.com说到它。

否则,不支持 IE 8 或 9(但也不足为奇),IE 10 支持旧版本的语法(自 2011 年起),并且部分支持 IE 11。有一些旧的 webkit 浏览器(Firefox 和 Safari)支持更旧版本的语法(从 2009 年开始)——你需要为这些支持 Flexbox 遗留(例如:2009 语法、2011 混合语法和浏览器前缀)的浏览器设置回退规则.

Advanced Cross-browser Flexbox

但是,如果您坚决避免使用 flex,那么您将不得不使用表格,或者放弃等高列的想法并坚持使用通用 inline-block 元素。

关于html - 循环中的等高 Bootstrap 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37566392/

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