表格单元格内的100%高度div不适用于Firefox

时间:2015-02-12 19:58:44

标签: html css css3

我尝试使用display table-cell属性创建两列100%高度布局。它在Chrome上工作正常,但我在Firefox和IE上都没有成功。

这是小提琴:http://jsfiddle.net/ehfa0kk8/5/

了解它在Chrome上的运作方式。知道如何使这项工作?

<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>

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

更新:首先,左栏应该有足够的内容,以便它会溢出。在Chrome上它会显示一个滚动条,因此您只能滚动该列(单元格)的内容。在Firefox上它并没有发生。

实施例: enter image description here

1 个答案:

答案 0 :(得分:7)

诀窍是:

  • 将行height设置为100%
  • 将单元格height设置为0

&#13;
&#13;
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;
}
&#13;
<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>
&#13;
&#13;
&#13;