That title might not be very accurate but here is the situation:
I was looking for a solution as well and since my HTML gets rendered through a CMS I couldn't use the solution of the accepted answer.
So my solution is:
.teaser {
// break into new line after last element
> div:last-child {
clear: right;
}
}
.teaser {
// two colums
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) {
> div:nth-child(2n+1) {
clear: left;
}
}
}
.teaser {
// three colums
@media (min-width: @screen-md-min) {
> div:nth-child(3n+1) {
clear: left;
}
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row teaser">
<div class="col-sm-6 col-md-4">div1</div>
<div class="col-sm-6 col-md-4">div2<br>more content</div>
<div class="col-sm-6 col-md-4">div3</div>
<div class="col-sm-6 col-md-4">div4</div>
<div class="col-sm-6 col-md-4">div5<br>more content content<br>content</div>
<div class="col-sm-6 col-md-4">div6</div>
<div class="col-sm-6 col-md-4">div7<br>more content</div>
<div class="col-sm-6 col-md-4">div8</div>
</div>
Hope this helps someone :-)
Looks like the only solution to your problem is to set a min-height or a fixed height to your elements to that there are no inconsistensies that cause your issues.
add this:
.file-row-contain {
min-height:250px;
}
...set height according to your needs
An .scss fix using bootstrap variables, taken from @jonas and @yog
@mixin row-first-child($col-type) {
.col-#{$col-type}- {
&1:nth-child(12n+1),
&2:nth-child(6n+1),
&3:nth-child(4n+1),
&4:nth-child(3n+1),
&6:nth-child(odd){
clear: left;
}
}
}
.auto-clear {
@media (min-width: $screen-lg-min){
@include row-first-child(lg);
}
@media (min-width: $screen-md-min) and (max-width: $screen-md-max){
@include row-first-child(md);
}
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max){
@include row-first-child(sm);
}
@media (max-width: $screen-xs-max){
@include row-first-child(xs);
}
}
Bootstrap 4 introduces hidden-*-up and hidden-*-down classes. Very handy (and elegant) utility for situations such as these.
Available classes
- The
.hidden-*-upclasses hide the element when the viewport is at the given breakpoint or wider. For example,.hidden-md-uphides an element on medium, large, and extra-large viewports.- The
.hidden-*-downclasses hide the element when the viewport is at the given breakpoint or smaller. For example,.hidden-md-downhides an element on extra-small, small, and medium viewports.- There are no explicit “visible”/”show” responsive utility classes; you make an element visible by simply not hiding it at that breakpoint size.
- You can combine one
.hidden-*-upclass with one.hidden-*-downclass to show an element only on a given interval of screen sizes. For example,.hidden-sm-down.hidden-xl-upshows the element only on medium and large viewports. Using multiple.hidden-*-upclasses or multiple.hidden-*-downclasses is redundant and pointless.- These classes don’t attempt to accommodate less common cases where an element’s visibility can’t be expressed as a single contiguous range of viewport breakpoint sizes; you will instead need to use custom CSS in such cases.
http://v4-alpha.getbootstrap.com/layout/responsive-utilities/