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.
An .scss fix using bootstrap variables, taken from @jonas and @yog
Bootstrap 4 introduces
hidden-*-up
andhidden-*-down
classes. Very handy (and elegant) utility for situations such as these.http://v4-alpha.getbootstrap.com/layout/responsive-utilities/
Adding to @Jonas and @KFunk's answer:
Potential fix for requiring the use of all col-sizes (col-xs-6 col-sm-4 col-md-4 col-lg-4).
Classes created: auto-clear-xs, auto-clear-sm, auto-clear-md and auto-clear-lg.
I've made my answer mobile-first.
Note: This still requires the columns to be the same size.
HTML
SCSS
CSS
You can fix this very easily with css if you don't need to support IE8.
See examples
In case your number of
col-
boxes in a row is DYNAMIC and different for resolution like it is in my case than based on yourcol-
classes do the modulus operator. Take example of below example.col-xs-6 means it has 2 boxes in a row for extra-small devices. so for it I've added that
$elementCounter % 2 == 0
condition so it is true for every second element ( AFTER ). and addedclearfix
withvisible-xs
so it shouldn't effect on desktop or other resolutions.col-sm-3 means 4 boxes in row for small and above devices so in that case i've added
$elementCounter % 4 == 0
and with thathidden-xs
so that clearfix is hidden for xs devices and will be visible for small and above. This way you can modify it accordingly.That is actually how it is supposed to be. The Bootstrap Grid consists of 12 columns, you're telling it to size one lg item to be 4/12 which is a third and an xs item to be 6/12 which is half the available width.
If you check the applied style you'll see that col-xs-6 is the same as setting the width of one item to 50% and 33.33% for col-lg-4.
You can read more about the grid system here
EDIT: I think I understand your problem now, without seeing your code I probably can't give you an exact solution. However the issue seems to be the variable height of your boxes, if you have them all at the same height it should give you the right amount of boxes per line.