My current layout looks like this:
<div class="container">
<div class="row">
<div class="col-md-8">1. Lorem</div>
<div class="col-md-4">2. Sollicitudin</div>
<div class="col-md-8">3. Lorem ipsum</div>
<div class="col-md-4">4. Pellentesque</div>
<div class="col-md-8">5. Donec efficitur</div>
<div class="col-md-4">6. Donec efficitur</div>
<div class="col-md-8">7. Lorem ipsum dolor</div>
</div>
</div>
In desktop mode, I want the columns to stack like this:
col-md-8 col-md-4
col-md-8 col-md-4
col-md-8 col-md-4
col-md-8 col-md-4
And in phone/tablet, I want the columns to stack like this: (starting with col-md-8)
col-md-8
col-md-4
col-md-8
col-md-4
col-md-8
col-md-4
col-md-8
col-md-4
I am having a big problem, the columns with the same class is not stacking vertically. Instead, they are leaving out a big "empty space". See fiddle of the empty space here.
I fixed this problem with the following CSS:
@media (min-width: 992px) {
.col-md-4 {
float: right;
}
}
See fiddle updated with new css - the columns are now stacking exactly as I want!
But, if col-md-8
is longer than the corrosponding col-md-4
, I get the same problems as before , see fiddle with same css as before, but with vertical empty space.
Desired output:
I want the columns with the same class to stack vertically regardless the height. The columns also have to adjust it's height dynamically depending on the amount of "content" it is inside, since this can't be predicted. I can't have columns with fixed heights.
Photoshopped image of the desired output.
I have tried to change the order of the columns, so col-md-4
comes first, this fixes it - see fiddle with updated column order. But in mobile/tablet, they stack in the wrong order (starting with col-md-4
) and if col-md-4
is longer it messes things up like in, see fiddle of this.
Does anyone know how how to solve this?