【发布时间】:2011-04-05 23:49:32
【问题描述】:
我遇到了以下问题:
如何制作通用容器(HTML + CSS;无 javascript)
是垂直约束的(它有一个固定的外部高度),所以它可能有一个垂直滚动条
但它可以水平增长(根据容器内容的需要),所以它永远不会有水平滚动条
它必须在 IE8、FF、Chrome(没有 IE7 或更早版本)中工作
解决方案一开始似乎很简单
但我无法摆脱 IE8 中的水平滚动条:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div style="display: table;" class="container-div-1">
<div style="display: table-cell;" class="container-div-2">
<div style="overflow-y: scroll; height: 19em;" class="container-div-3">
<div style="width: 30em; height: 30em; background-color: red;" class="example-content"></div>
</div>
</div>
</div>
</body>
</html>
在本例中,我们需要一个 19em 高的容器,它可以根据内容的需要水平增长(在本例中为“example-cotent”div)
请不要建议修改“example-content” div,因为它只是一个示例内容(任何内容都可以存在)
这个问题是这个问题的概括: IE8 horizontal scrollbar problem
【问题讨论】:
-
重要:容器不应该水平扩展,只要内容需要(这就是外部 CSS 表存在的原因)
-
我发了一个后续问题:stackoverflow.com/questions/5558592/…