html - 表格单元格内的 100% 高度 div 在 Firefox 上不起作用

标签 html css

我正在尝试使用 display table-cell 属性创建一个两列 100% 高度的布局。它在 Chrome 上运行良好,但我在 Firefox 和 IE 上都没有成功。

这是 fiddle :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

最佳答案

诀窍是:

  • 将行的高度设置为100%
  • 将单元格的高度设置为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>

关于html - 表格单元格内的 100% 高度 div 在 Firefox 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28486685/

相关文章:

javascript - 为什么从 onclick 属性调用的函数 write() 解析为 document.write()?

javascript - 如何强制jquery触发函数触发for循环中的所有事件?

html - 将两个方 block 排成一行,避免它们相互重叠

css - 我可以使用 Sublime 在 Visual Studio 2010 元素中编辑 CSS 文件吗

css - IFrame 中缺少样式(Asp.Net 页面)

javascript - 如何在没有 innerHTML = ""的情况下清除 div 的内容;

html - 无法增加超大屏幕宽度

css - 如何使用border-bottom为链接下划线设置动画,以便链接文本和下划线之间有空间?

javascript - 将 <ol type ="a"> 的所有出现动态更新为 <ol class ="alpha">

html - 只使用css transform translate来控制动画而不是margin等非优化