【发布时间】:2010-10-18 20:33:28
【问题描述】:
这在 30 行上按预期工作,但在插入后增加了超过 50% 的块高度,例如100 行。谁能解释会发生什么?我只在 FF 中注意到了这个错误。
<!DOCTYPE html>
<html style="height:100%;">
<head>
<title></title>
</head>
<body style="height:100%;background:grey;padding:0;margin:0;">
<table style="height:100%;">
<tr>
<td style="height:100%;">
<div style="background:white;height:50%; overflow: auto">
<script>
// try 100 to see a bug
for (i = 0; i <= 30; i++) {
document.write(i + " Sample text<br>");
}
</script>
</div>
<div style="background:blue; height:50%">
Sample text
</div>
</td>
</tr>
</table>
</body>
</html>
【问题讨论】:
-
你为什么在这里使用表格?省略的结果会不会完全一样?
-
在这种情况下表格看起来完全没用,您是否尝试过删除它会发生什么?如果您手动将溢出设置为“滚动”会发生什么?
-
@elusive 不会。但我需要在我的页面上使用表格。我只是简化了
-
那么
tbody和tr的高度呢?这些在这里没有定义。百分比值总是有点棘手。 -
@elusive 将 tbody 高度设置为 100% 解决了这个问题。多谢!如果你愿意,你可以写一个我会接受的答案。