0

I have a structure similar to the following:

<div class="cell-row">
    <div class="cell">
        //Some tall content
    </div>
    <div class="cell">
        //Some short content
    </div>
</div>

So basically there are a bunch of inline-block cells next to each other. They all contain content of various heights. I have a min-height set on the parent container, and I want them to all fill the parent container (in height) so that they look like a table.


However, with my current CSS, the tallest one fills the parent, and all of the rest only fill based on their content height.

Here's a JSFiddle demonstrating what I am talking about. I want the box with the 2 in it to be the same height as the box with the 1 in it.


Here's the relevant CSS:

div.cell-row
{
    min-height: 150px;
}

div.cell
{
    display: inline-block;
    vertical-align: top;

    box-sizing: border-box;
    -moz-box-sizing: border-box;
    padding: 10px;
    height: 100%;
}

I would think that the height: 100%; would make all of the cells fill the parent .cell-row height, but it doesn't.

JSFiddle

Community
  • 1
  • 1
Liftoff
  • 24,717
  • 13
  • 66
  • 119
  • 1
    If you want a table, why not use `table`? – Drew Gaynor Dec 16 '14 at 19:34
  • Honestly, because I've already built this design, and I don't want to have to redo it if I don't have to :P My question still stands though. – Liftoff Dec 16 '14 at 19:36
  • possible duplicate of [CSS – why doesn’t percentage height work?](http://stackoverflow.com/questions/5657964/css-why-doesn-t-percentage-height-work) - Specifically the part about "[percentage height] doesn't yield a well defined value unless you ... [give] the parent element a specific height." – showdev Dec 16 '14 at 19:38
  • Understood. And I agree, it's still a good question independent of the rationale for the design. – Drew Gaynor Dec 16 '14 at 19:39
  • are you looking for thi??? http://jsfiddle.net/680r224b/5/ – Manjunath Siddappa Dec 16 '14 at 19:42
  • possible duplicate of [Stretch child div height to fill parent that has dynamic height](http://stackoverflow.com/questions/17900122/stretch-child-div-height-to-fill-parent-that-has-dynamic-height) – disinfor Dec 16 '14 at 19:59

2 Answers2

3
div.cell-row
{
    display : table-row;
    ...
}

div.cell
{
    display : table-cell;
    ...
}

http://jsfiddle.net/680r224b/2/


To make the table still fill the container, and to make min-height work, use:

div.cell-row
{
    display : table;
    ...
}
Liftoff
  • 24,717
  • 13
  • 66
  • 119
AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • So how do I make the "row" fill the width of the page, as putting `width: 100%` doesn't seem to do anything. – Liftoff Dec 16 '14 at 19:38
  • Yeah. The `min-height` and `width` attributes of the container are now ignored. – Liftoff Dec 16 '14 at 19:41
  • @Patrick Ah I see. You changed the `.cell-row` to `display: table`. In that case, it works. – Liftoff Dec 16 '14 at 19:42
  • @David Yes, I looked too quickly at the answer above and thought it was the exact same as mine. I guess I should have posted mine separately. I posted it now. – Patrick Dec 16 '14 at 19:44
2

html, body
{
    margin: 0;
    height: 100%;
}

div.cell-row
{
    min-height: 150px;
    background: #111;
    display:table;
    width:100%;
    font-size: 0;
}

div.cell-row div.cell
{
    display: inline-block;
    vertical-align: top;
    display:table-cell;
    
    border-right: 1px solid #aaa;
    background: #ccc;
    
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    
    width: 50%;
    padding: 10px;
    height: 100%;
}

div.cell-row div.cell p
{
    font-size: 80px;
}
<div class="cell-row">
    <div class="cell">
        <p>1</p>
        <p>test</p>
    </div>
    <div class="cell">
        <p>2</p>
    </div>
</div>
Patrick
  • 872
  • 1
  • 5
  • 14
  • Well since you did answer my question fully (since I was the one who edited in your answer to AlienWebGuy's answer), I'll award you the answer then. – Liftoff Dec 16 '14 at 19:47