That title might not be very accurate but here is the situation:
As you can see in the HTML, The grid system goes from 4 images on xl screens to 3 on lg screens to 2 on anything less.
I am trying to get it to display properly - the proper amount of images at each screen size, that is. However, something funky is going on and can't quite figure it out using bootstraps classes.
It seems to me that I would have to add rows dynamically at each break-point.
Any suggestions?
-- UPDATE -- Just realized that col-xl-* doesn't exist. However, that does not change the situation at all. Please disregard the xl declaration.
-- UPDATE 2 -- Updated images.
-- UPDATE 3 -- I'll try to clarify my goal. For that specific image attached in my post, I would like for 3 boxes to appear per row - not all helter skelter.
When it collapses down to 2 boxes per row (xs device), I want to make sure every row has 2 boxes.
The reason why your layout is breaking is due to the dynamic height of the images being presented. The fix is simple though, just constrain the height of the images. For example
HTML
CSS
Check out the CodePen to see it in action. Hope this helps.
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:
...set height according to your needs
I solved this issue by adding
clearfix
elements where they should be. I wanted 3 columns onmd
and 2 columns onsm
and this is how I did it:So i used
clearfix visible-sm
after every second div andclearfix visible-md
after every third div. I don't find this solution ideal, but it works rather well.EDIT: As of Bootstrap v3.2.0
.visible-*
classes are deprecated.http://getbootstrap.com/css/#responsive-utilities:
The classes .visible-xs, .visible-sm, .visible-md, and .visible-lg also exist, but are deprecated as of v3.2.0. They are approximately equivalent to .visible-*-block, except with additional special cases for toggling -related elements.
EDIT 2: This solution works as long as you do not want to edit CSS, if you have the option to do so, I recommend you use Jonas's answer as it is much simpler in my opinion.
Extend your bootstrap.css with this css:
Use it like:
Note: this requires the use of all col-sizes and that all cols are of the same size.
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:
Hope this helps someone :-)