4

I'm trying to create a two column 100% height layout using the display table-cell property. It is working fine on Chrome, but I'm not having success on Firefox nor IE.

Here is the fiddle: http://jsfiddle.net/ehfa0kk8/5/

Take a look at how it works on Chrome. Any idea of how to make this work?

<div id="table">
    <div id="row">
        <div id="cell_1">
            <div id="overflown_div">
                long content goes here...
            </div>
        </div>
        <div id="cell_2">
            Blah blah blah
        </div>
    </div>
</div>

And the CSS

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

#table {
    width: 100%;
    display: table;
    height: 100%;
}

#row {
    display: table-row;
}

#cell_1, #cell_2 {  
    display: table-cell;
    height: 100%;
}

#cell_1 {
    width: 390px;
    background: aliceblue;
}

#cell_2 {
    background: yellow;
}

#overflown_div {
    height: 100%;
    overflow: scroll;
    padding: 10px;
}

UPDATE: First, there should be enough content on the left column so it will overflow. On Chrome it shows a scroll bar so you can scroll just the content of that column (cell). On Firefox it doesn't happen.

EXAMPLE: enter image description here

lbrandao
  • 4,144
  • 4
  • 35
  • 43
  • What isn't working? I see 2 full height columns in Firefox. – Matthew Rapati Feb 12 '15 at 20:02
  • First, I don't know how big is your screen, but there should be a long content on the left column so it will overflown. On Chrome it shows a scroll bar so you can scroll just the content of that column (cell). On Firefox it doesn't happen – lbrandao Feb 12 '15 at 20:03
  • looks fine here on firefox, can you post a screenshot to explain the problem. – Stickers Feb 12 '15 at 21:08
  • @sdcr, I just did. Notice the scrollbar on the overflown div on Chrome, but on Firefox the 100% height doesn't work. – lbrandao Feb 12 '15 at 22:19

1 Answers1

19

The trick is:

  • Set row's height to 100%
  • Set cell's height to 0

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
#table {
  width: 100%;
  display: table;
  height: 100%;
}
#row {
  display: table-row;
  height: 100%;
}
#cell_1,
#cell_2 {
  display: table-cell;
  height: 0;
}
#cell_1 {
  width: 390px;
  background: aliceblue;
}
#cell_2 {
  background: yellow;
}
#overflown_div {
  height: 100%;
  overflow-y: scroll;
  padding: 10px;
  box-sizing: border-box;
}
#overflown_div p {
  height: 80px;
}
<div id="table">
  <div id="row">
    <div id="cell_1">
      <div id="overflown_div">
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
        <p>Blah blah blah</p>
      </div>
    </div>
    <div id="cell_2">
      Blah blah blah
    </div>
  </div>
</div>
Oriol
  • 274,082
  • 63
  • 437
  • 513
  • It works for Firefox, but not for IE. Any logic behind that? – lbrandao Feb 12 '15 at 20:27
  • 1
    It works if you set both to 100% and if you only target Firefox. Chrome, on the other hand, needs the cell to have a **fixed** height, even zero. Full solution is: `th, td { height: 0; } @-moz-document url-prefix() { tr, th, td { height: 100%; } }` (use them in that order) – Tobia Jun 29 '21 at 15:05