简体   繁体   English

Bootstrap列未正确对齐

[英]Bootstrap columns does not align correctly

I have a weird bug in my columns that I can't identify, I don't know if it is my fault or a bootstrap thingy. 我的列中有一个无法识别的怪异错误,我不知道这是我的错还是自举。

Basically, I have a single <div class="row"> that may contains many <div class="col-lg-2 col-md-2 col-sm-3 col-xs-4"> . 基本上,我只有一个<div class="row"> ,其中可能包含许多<div class="col-lg-2 col-md-2 col-sm-3 col-xs-4"> What I simply wants to achieve is that all col* items fit on the screen (100% width) and aligning each other when resizing. 我只是想实现的是,所有col *项目都适合屏幕(宽度为100%),并且在调整大小时彼此对齐。 This works very well normally, except in this JSFiddle . 除此JSFiddle之外,这通常可以很好地工作

The problem is that on some rows, one div goes completly crazy and will not align correctly in the row (try to resize slowly the result in the fiddle, you will see what I mean). 问题在于,在某些行上,一个div会完全发疯,并且无法在行中正确对齐(尝试在小提琴中缓慢调整结果的大小,您会明白我的意思)。

I'm using bootstrap 3.3.6 and Chrome to its latest version (tried on FF, same weird result...). 我正在使用bootstrap 3.3.6和Chrome到最新版本(在FF上尝试,结果很奇怪...)。 "clearfix" does nothing. “ clearfix”什么都不做。 I have tried packery.js with the same result. 我尝试了packery.js,结果相同。

This answer ( Bootstrap columns not aligning correctly ) would have helped me, but I don't know in advance how many columns I will have (because that will depend on the screen size) ... 这个答案( Bootstrap列无法正确对齐 )对我有帮助,但是我事先不知道会有多少列(因为这取决于屏幕尺寸)...

Of course, I have tried setting min-height to each .gallery-item ... 当然,我尝试过为每个.gallery-item设置最小高度...

Any ideas ? 有任何想法吗 ?

Thanks in advance, 提前致谢,

Update , here are the missing CSS that appears in my code: 更新 ,这是我的代码中出现的缺少的CSS:

div.gallery-item {
    margin-bottom: 15px;
}

div.gallery-item, div.gallery-item * {
    -webkit-transition: all 300ms;
    -moz-transition: all 300ms;
    transition: all 300ms;
}

.gallery-item {
    cursor: pointer;
}

.gallery-item.active {
    background-color: rgba(128,192,255,0.5);
}

Second update , following the advices, I get it to work by adding a fixed height for each gallery-item, like that: 第二次更新 ,根据建议,我通过为每个图库项目添加固定高度来使其正常工作,如下所示:

.gallery-item {
  height: 300px;
}

Thanks to all :) 谢谢大家 :)

The problem is because not all columns inside the row are equal height. 问题是因为并非行内的所有列都具有相等的高度。 Have a look at the following to ensure the equal column height. 请看以下内容以确保相等的柱高。

Link here 连结这里

Updated you Fiddle with this approach, have a look at updated Fiddle 用这种方法更新了您的Fiddle,看看更新的Fiddle

Added CSS 添加了CSS

.row-eq-height {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display:         flex;
}

Added CSS class to the gallery-item 将CSS类添加到gallery-item

row-eq-height gallery-item 

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

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