0

I know this is an old question, but still not able to get any workable css solution.

The boxes should grow in height to accommodate all the dynamic content. The box with the maximum height should set the height of all the other boxes, so that all get the same height.

Note:
1) It should work till IE-8. And there could be too many boxes so dont limit it to 2 or 3 boxes.
2) I tried padding-bottom, negative margin bottom and table cell method. Cant use flex box as it wont support to IE9.
3) Cant change the HTML structure.

HTML:

<ul>
  <li>
    <div class="tile">
    <div class="img"><img src="http://placehold.it/100x50">
    </div>
    <div class="name">
      Lorum Ipsum Lorum  
    </div>
   </div>
  </li>

  <li>
    <div class="tile">
    <div class="img"><img src="http://placehold.it/100x50">
    </div>
    <div class="name">
      Lorum Ipsum Lorum  Lorum Ipsum Lorum
    </div>
   </div>
  </li>

  <li>
    <div class="tile">
    <div class="img"><img src="http://placehold.it/100x50">
    </div>
    <div class="name">
      Lorum Ipsum Lorum  Lorum Ipsum Lorum
    </div>
   </div>
  </li>

  <li>
    <div class="tile">
    <div class="img"><img src="http://placehold.it/100x50">
    </div>
    <div class="name">
      Lorum Ipsum Lorum  
    </div>
   </div>
  </li>

  <li>
    <div class="tile">
    <div class="img"><img src="http://placehold.it/100x50">
    </div>
    <div class="name">
      Lorum Ipsum Lorum  
    </div>
   </div>
  </li>
</ul>

CSS:

ul{
  margin:0;
  padding:0;
  width:600px; 
  margin:0 auto;
  border:#999 solid 1px;
  border-bottom:none;
  border-right:none;
  overflow:hidden;
}
li{
  float:left;
  list-style:none;
  width:25%;
  padding:0;
  margin:0;
  box-sizing:border-box;
  border-right:#999 solid 1px;
  border-bottom:#999 solid 1px;
  text-align:center;
  padding:5px;
}

example: http://codepen.io/anon/pen/GFeoc

Praveen
  • 1,772
  • 3
  • 24
  • 42

3 Answers3

1

For a CSS solution, try replacing float:left with display:table-cell on your li selector and add display:table; table-layout:fixed to your ul selector.

Example

Talmid
  • 1,273
  • 14
  • 19
1

It's very simple, add this to your js file in CodePen and it will work:

$( document ).ready(function() {
    var heights = $("li").map(function() {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);

    $("li").height(maxHeight);
});

Check here http://codepen.io/anon/pen/IFmkq

paulalexandru
  • 9,218
  • 7
  • 66
  • 94
  • 1
    I understand that, the problem is that you won't find one because it does not exist, or it does exist something but it doesn't work on all browsers. – paulalexandru Oct 31 '14 at 07:14
0

Some simple JavaScript (jQuery) will do the trick.

DEMO

equalHeight($('.tile'));

function equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}
Schmalzy
  • 17,044
  • 7
  • 46
  • 47