83

Here is 2 column markup using display: table and display: table-cell CSS declarations:

.table {
  display: table;
}

.cell {
  border: 2px solid black;
  vertical-align: top;
  display: table-cell;
}

.container {
  height: 100%;
  border: 2px solid green;
}
<div class="table">
  <div class="cell">
    <p>Text
      <p>Text
        <p>Text
          <p>Text
            <p>Text
              <p>Text
                <p>Text
                  <p>Text
  </div>
  <div class="cell">
    <div class="container">Text</div>
  </div>
</div>

But .container block does not fill parent cell vertically. Here is an example on JsFiddle: http://jsfiddle.net/MGRdP/2.

What I have | What I need

What I have What I need

Please, do not propose JS solution.

Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21
Paul Annekov
  • 3,193
  • 3
  • 19
  • 31
  • 6
    The issue is that you are using `height: 100%;` for child element whose parent `height` is set to `auto`, so inorder to fix this, assign `height: 100%;` to all the parents, and if not, than use some fixed `height` for `.cell` – Mr. Alien Mar 06 '14 at 09:55
  • 3
    +1 for no JS solution. – John Sep 04 '14 at 22:05

7 Answers7

57

When you use % for setting heights or widths, always set the widths/heights of parent elements as well:

.table {
    display: table;
    height: 100%;
}

.cell {
    border: 2px solid black;
    vertical-align: top;
    display: table-cell;
    height: 100%;
}

.container {
    height: 100%;
    border: 2px solid green;
    -moz-box-sizing: border-box;
}
<div class="table">
    <div class="cell">
        <p>Text
        <p>Text
        <p>Text
        <p>Text
        <p>Text
        <p>Text
        <p>Text
        <p>Text
    </div>
    <div class="cell">
        <div class="container">Text</div>
    </div>
</div>
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
anurupr
  • 2,294
  • 2
  • 20
  • 28
55
table{
   height:1px;
}

table > td{
   height:100%;
}

table > td > .inner{
   height:100%;
}

Confirmed working on:

  • Chrome 60.0.3112.113, 63.0.3239.84
  • Firefox 55.0.3, 57.0.1
  • Internet Explorer 11
Valera Tumash
  • 628
  • 7
  • 16
Danila Alpatov
  • 822
  • 7
  • 11
27

set height: 100%; and overflow:auto; for div inside .cell

hd.deman
  • 1,268
  • 12
  • 17
20

In Addition to jsFiddle, I can offer an ugly hack if you wish in order to make it cross-browser (IE11, Chrome, Firefox).

Instead of height:100%;, put height:1em; on the .cell.

Nathan Arthur
  • 8,287
  • 7
  • 55
  • 80
Saar
  • 2,276
  • 1
  • 16
  • 14
  • Can you explain why changing height: 100% to height: 1em; works? 1em should just be the height of the letter "m" .... Funny, I have a similar issue as above and changing to height:1em fixed my issue across the board. Kudos! NOTE* I did not do anything else like changing position etc... – Wes Duff Jan 11 '16 at 20:44
  • 1
    I'm not sure if its ugly, but it works. Wish I knew why. – Casey Plummer Feb 17 '17 at 04:37
  • `height: 1px;` works for me. And in my opinion, this is better than setting it on the entire table as suggested in another answer. – Tigran Mar 28 '23 at 14:58
11

Make the the table-cell position relative, then make the inner div position absolute, with top/right/bottom/left all set to 0px.

.table-cell {
  display: table-cell;
  position: relative;
}

.inner-div {
  position: absolute;
  top: 0px;
  right: 0px;
  bottom: 0px;
  left: 0px;
}
Abdalla Mahmoud
  • 111
  • 1
  • 4
7

This is exactly what you want:

HTML

<div class="table">

    <div class="cell">
        <p>Text</p>
        <p>Text</p>
        <p>Text</p>
        <p>Text</p>
        <p>Text</p>
        <p>Text</p>
        <p>Text</p>
        <p>Text</p>
    </div>
    <div class="cell">
        <div class="container">Text</div>
    </div>
</div>

CSS

.table {
    display: table;
    height:auto;
}

.cell {
    border: 2px solid black; 
    display:table-cell;
    vertical-align:top;
}

.container {
    height: 100%;
    overflow:auto;
    border: 2px solid green;
    -moz-box-sizing: border-box;
}
Ernest Sawyer
  • 360
  • 2
  • 13
4

Define your .table and .cell height:100%;

    .table {
        display: table;
        height:100%;
    }

    .cell {
        border: 1px solid black;
        display: table-cell;
        vertical-align:top;
height: 100%;

    }

    .container {
        height: 100%;
        border: 10px solid green;

    }

Demo

Rohit Azad Malik
  • 31,410
  • 17
  • 69
  • 97
  • 1
    None of those solutions worked on Bootstrap elements: table element is a raw, cell element is a col-lg and the container is a panel – Yazid Erman Nov 18 '15 at 05:10