简体   繁体   English

如何使用Twitter Bootstrap使彼此附近的div具有相同的高度

[英]How to make divs near eachother to have the same height with twitter bootstrap

I have a page with a variable numbers of child divs, that depending on screen resolution they come 4 in a row (desktop), 3 in a row (tablet) or 2 in a row (on smartphones). 我有一个页面,其中的子div数目不固定,取决于屏幕分辨率,它们连续4个(桌面),连续3个(平板电脑)或连续2个(在智能手机上)。 But their content differ. 但是它们的内容不同。 How could I make divs that are in a line, have the same height? 如何使一行中的div具有相同的高度? I have an example here 这里有一个例子

<div class="row">
    <div class="col-md-3 col-sm-4 col-xs-6">
        asdfas<br />
        asdfas
    </div>
    <div class="col-md-3 col-sm-4 col-xs-6">
        asdfas
    </div>
    <div class="col-md-3 col-sm-4 col-xs-6">
        asdfas<br />
        asdfas
    </div>
    <div class="col-md-3 col-sm-4 col-xs-6">
        asdfas<br />
        asdfas
    </div>
    <div class="col-md-3 col-sm-4 col-xs-6">
        asdfas
    </div>
    <div class="col-md-3 col-sm-4 col-xs-6">
        asdfas<br />
        asdfas
    </div>
</div>

In this case, go for display:flex 在这种情况下,请进行显示:flex
or jquery grid layout plugins jQuery网格布局插件

You should manually set the height of the divs. 您应该手动设置div的高度。 Find out what height (probably in pixels) is appropriate for the largest div, and then set them all to that size. 找出适合最大div的高度(可能以像素为单位),然后将它们全部设置为该大小。

Put an Id on the row class so you can use it as a selector 将ID放在行类上,以便将其用作选择器

<div class="row" id=selectorID>

Then try add a min-height on the child divs 然后尝试在子div上添加最小高度

#selectorID > div[class^='col-']{ min-height: 200px; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM