Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

100% height div inside table-cell not working on Firefox

Tags:

html

css

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

like image 525
fromvega Avatar asked Dec 03 '22 17:12

fromvega


1 Answers

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>
like image 88
Oriol Avatar answered Jan 11 '23 13:01

Oriol