Liftoff
Liftoff

Reputation: 25372

Filling parent height for all divs

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

Upvotes: 0

Views: 102

Answers (2)

Patrick
Patrick

Reputation: 882

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>

Upvotes: 2

SeanCannon
SeanCannon

Reputation: 77956

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;
    ...
}

Upvotes: 3

Related Questions