简体   繁体   English

Firefox中100%高度div上不显示溢出滚动条

[英]Overflow scrollbar not showing on 100% height div in Firefox

I have recreated a CSS compatibility issue I have come across between Chrome and Firefox. 我已经重新创建了在Chrome和Firefox之间遇到的CSS兼容性问题。

An "inner" DIV with 100% height inside a Table cell which is inside a "container" DIV of fixed height. 在表格单元格内具有100%高度的“内部” DIV,该单元格在固定高度的“容器” DIV内。 I want the inner DIV to fill the cell and dynamically add text to it such that a scrollbar appears when it begins to overflow. 我希望内部DIV填充单元格并向其中动态添加文本,以便在滚动条开始溢出时出现滚动条。

In the JSFiddle you can see the code in both Chrome and Firefox. 在JSFiddle中,您可以在Chrome和Firefox中看到代码。 In Chrome it behaves as expected but in Firefox the scrollbar doesn't display and the inner DIV just keeps expending beyond the height of the container DIV. 在Chrome浏览器中,它的行为符合预期,但在Firefox中,滚动条不会显示,内部DIV只会不断超出容器DIV的高度。

JSFiddle code to try in both Chrome and Firefox 可在Chrome和Firefox中尝试的JSFiddle代码

HTML as follows: HTML如下:

<style>
#container {
  height:80px;
  width:100%;
  border:1px solid;
  overflow:hidden;
  resize:vertical;
}

#inner {
  height:100%;
  width:300px;
  border:2px solid red;
  overflow-y:auto;
}

table{
  height:100%;
}
</style>

<div id="container">
<table>
<tr>
  <td>
  <div id="inner">
    Test<br/>Test<br/>Test<br/>Test<br/>Test<br/>
  </div>
  </td>
  <td>
  <img src="https://doc-snapshots.qt.io/qt-mobility/images/used-in-examples/video/qmlvideo/images/close.png" />
  </td>
</tr>
</table>
</div>

EDIT, further requirement: I forgot to mention that I have this setup inside a resizable DIV ie the Container DIV is able to resize it's height so that the table and Inner DIV resize accordingly. 编辑,进一步的要求:我忘了提及我在可调整大小的DIV中具有此设置,即Container DIV能够调整其高度,以便表格和Inner DIV相应地调整大小。

#inner {
      border: 2px solid red;
      height: 75px;
      overflow: auto;
      width: 300px;
    }

You can use this CSS. 您可以使用此CSS。 I think it may work fine. 我认为这可能很好。

Thats a common mistake. 那是一个常见的错误。 Whenever an element is set to height: 100% or any other percentage, it relates to the height of its parent. 每当将元素设置为height: 100%或任何其他百分比时,它均与其父级的height相关。 So when using this, its important to define a height for the parent of your element: 因此,使用此参数时,为元素的父级定义height很重要:

To demonstrate the problem: Adding a class to the parent <td class="fix"> and add some css fixes the problem: 演示问题:将类添加到父<td class="fix">并添加一些CSS可以解决此问题:

.fix {
  height: 80px;
  display: block;
}

WORKING JSFIDDLE DEMO 工作JSFIDDLE演示

Keep in mind that setting the display attribute of a table cell from table-cell to block is something you should avoid, as you are changing the elements roots. 请记住,在更改元素根时,应避免将表单元的display属性从table-cellblock Consider a solution without using a <table> markup if you have got the possibilities. 如果有可能,请考虑不使用<table>标记的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM