How to organize many divs in Bootstrap (Image)

1

How do I organize many col-xx-3 divs of different heights ?
Is there any class or some other method without using row (every 4 products)?
Any way does not need to change Select or PHP ?



I have tried in many ways but I have not been able to. I tried to change Select already, and PHP too, but I always fell into some bigger problem.

Remembering that I do not have much practice. I'm open to any ideas!

Thank you all!

(some things in the layout will still change, the image is just demo)

    
asked by anonymous 19.04.2016 / 16:31

4 answers

2

Well, on the margin between the div's, just change the CSS on your page by changing the margin.

.col-md-3{
  margin: 0 5px 5px 0;
}

In terms of size, I do not think you know the size of each text to set min-heigth of the page, so I recommend using jQuery to get the largest size of each div and set heigth equal for all. It would look something like this:

 $(document).ready(function() {
   var maxHeight = -1;

   $('.col-md-3').each(function() {
     maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
   });

   $('.col-md-3').each(function() {
     $(this).height(maxHeight);
   });
 });

See an example working on JsFiddle.

References: Use jQuery / CSS to find the tallest of all elements.

If you want to change the size in blocks, you can separate the value of maxHeigth in each block, like this:

$(document).ready(function() {
   var maxHeight = -1;

      $('.row').each(function() {

       $(this).find('.col-md-3').each(function() {
         maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
       });

       $(this).find('.col-md-3').each(function() {
         $(this).height(maxHeight);
       });

   });
 });

Functional example in JsFiddle .

    
19.04.2016 / 17:12
1

You can set a maximum fixed height for the elements, in your case there, the items are crowding because there are some with height greater than the other. If you put the height of the class="col-sm-3" in that case then in 200px for example by default, it will solve the problem!

    
19.04.2016 / 16:36
1

You can do a PHP, creating a sum before listing each list, if the sum is = 4 which is the amount of Li per line, plays a clearfix div and zeros the sum to redo, another tip is to use the mansory , have you heard of it? follows a few links, it adjusts the Li: link link

If you want to follow the example in php, play the code in the plunker that I help you with!

    
19.04.2016 / 16:42
1

The best way is with the "row" class

    
19.04.2016 / 18:42