Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 3 same height fluid grid layout?

I need same height to layout box product in my website ! you can see image below enter image description here

when im using "clearfix" for break like it work fine , so when display in small sreen (mobile device) this same like image below , i think problem for height of the box !

because i load product in mysql data below code

 <div class="row">
 <?php foreach($contens as $content){?>
  <div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
   <div class="contents-block">
    <div class="image"><img href="<?php echo $content['image'];?>" />
    </div>
        ................ some code .............
   </div>
  </div>
<?php } ?>

i need all box is same height to display like in my design ! any idea for this !

like image 226
Peter Jack Avatar asked Oct 25 '13 17:10

Peter Jack


People also ask

How do I make Bootstrap 3 columns equal height?

You should be using a custom selector for one and two the tables styles should not be applied to [class*='col-'] that have defined widths. This method should ONLY be used if you want equal height AND equal width columns. It is not meant for any other layouts and is NOT responsive.

How do I make a div the same height in a row?

Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.

What is XS SM MD LG in Bootstrap?

The Bootstrap grid system has four classes: xs (for phones - screens less than 768px wide) sm (for tablets - screens equal to or greater than 768px wide) md (for small laptops - screens equal to or greater than 992px wide) lg (for laptops and desktops - screens equal to or greater than 1200px wide)

What is Col MD 6 in Bootstrap?

col-sm- (small devices - screen width equal to or greater than 576px) . col-md- (medium devices - screen width equal to or greater than 768px) . col-lg- (large devices - screen width equal to or greater than 992px)


2 Answers

If you don't want to truncate the content, there are 2 possible ways to deal with it.

1. use <div class="clearfix visible-xs"></div>

suggested here: https://github.com/twbs/bootstrap/issues/9454

It's easy to understand, but generates empty clearfix divs, which I personally consider it's polluting the markup. Plus if you're looping the collection dynamically things could get worse, you may end up using code like this:

<% @posts.each do |post| %>
  <div class="col-sm-6 col-md-4">
    <%= post.body %>
  </div>

  <% unless index == 0 %>
    <% # add a visible clearfix every 3 posts in medium ~ large screen, respond to col-md-4 %>
    <% if index % 2 == 0 %>
      <div class="clearfix visible-md visible-lg"></div>
    <% # add a visible clearfix every 2 posts in small screen, respond to col-sm-6 %>
    <% elsif index % 1 == 0 %>
      <div class="clearfix visible-sm"></div>
    <% end %>
  <% end %>
<% end %>

2. use css nth-child selector

First suggested in this issue: https://github.com/twbs/bootstrap/issues/9454

It's reusable, keep the code clean, but have to add extra stuff to make it work. Also have to remember the one tiny syntax for it: <div class="row multi-columns-row">

https://github.com/sixfootsixdesigns/Bootstrap-3-Grid-Columns-Clearing

I encountered the same issue, for me I probably will go the 2nd solution.

like image 57
kinopyo Avatar answered Oct 08 '22 01:10

kinopyo


IMHO one of these libs would be a better solution:

http://isotope.metafizzy.co/ http://masonry.desandro.com/

like image 33
tomByrer Avatar answered Oct 08 '22 01:10

tomByrer