【发布时间】:2013-01-30 10:57:48
【问题描述】:
我在固定位置有一个红色 div:顶部和底部是固定的。
这个div包含一个表格,其中一个单元格包含一个可滚动的div,这样内容就不会溢出红色的div。
在 Chrome 上看起来像这样:
但在 Firefox 上,内容会增长并溢出红框:
这是我的 HTML:
<div id=a>
<div id=b>
<table id=c border=1>
<tr><th height=20 width=20>
<input type=button id=but value="Fill cell">
</th><th>A</th></tr>
<tr><th>dataname</th>
<td><div id=val class=scrollable>cell content</div></td>
</tr>
</table>
</div>
</div>
和 CSS :
#a {
position:fixed; top:20px; left:20px; bottom:50px;width:200px;
background:red;
}
#b { height:100%; }
#c { width:100%; height:100%; }
.scrollable {
width:100%; height:100%;
overflow-y:auto;
}
这是测试的小提琴:http://jsfiddle.net/xusqc/
我建议您在提交答案之前在 FF 上测试您的提案。
如何修复我的代码,使其在 Firefox 和 IE9+ 上具有我现在在 Chrome 上的行为?
请注意,表格第一行的高度可能会在我的应用程序中动态变化。如果我的数据表有更多的行和单元格,则该解决方案必须适用。
【问题讨论】:
-
@queueoverflow 它不起作用,我不希望滚动条在不需要时出现。
-
在 td 中使用 div 不是一个好习惯,为什么不将 id 和 class 传递给 div 的父 td?只是一个建议
-
@Ark 如果它可以重现我需要的行为(并且我现在在 Chrome 上),我很乐意使用更好的做法。我的 td 中有一个 div 的原因是 td 不能滚动。
标签: css html internet-explorer firefox