【发布时间】:2012-06-02 23:34:42
【问题描述】:
我正在使用容器 (div) 进行布局,容器内有两个元素,一个 div 用于标题,另一个 div 用于内容。 标题 div 有一个固定的高度,内容的 div 必须填满可用空间。 容器 div 有自己的样式,不能重叠。 我的目标是创建简单的基于 div 的元素来在网页上放置简单的小部件。
我检查了其他类似的问题,例如:
- How to make a div expand to fit available vertical space?
- Force to fill all available vertical space
- Add a DIV that takes up all available vertical space
但是这些解决方案都不适用于我。
我设法得到了这个 html/css:
<?xml version="1.0"?>
<html>
<head>
<style type="text/css">
.workbench {
width: 100%;
height: 100%;
background: white;
}
.widget {
width: 100px;
height: 500px;
position: absolute;
top: 50px;
left: 50px;
border: solid 1px black;
margin: 2px;
}
.widget-header {
height: 50px;
border: solid 1px red;
margin: 2px;
}
.widget-body {
position: absolute;
top: 50px;
bottom: 0px;
left: 0px;
right: 0px;
border: solid 1px blue;
overflow: hidden;
margin: 2px;
}
</style>
</head>
<body>
<div id="workbench" class="workbench">
<div id="widget" class="widget">
<div id="widget-header" class="widget-header">
Header
</div>
<div id="widget-body" class="widget-body">
Body
</div>
</div>
</div>
</body>
</html>
这在 FireFox 和 Chrome 上很有效,但在 Internet Explorer 8 上不起作用:
你能帮帮我吗?
【问题讨论】:
-
您在哪个版本的 Internet Explorer 上进行测试?
-
为此制作了fiddle 并在几乎所有 IE 版本上呈现,并且该问题似乎仅在版本 6 和 5.5 上重现。 你真的想去那里吗?
-
使用小提琴IE8显示兼容性视图按钮并且渲染是正确的,从本地文件加载html结果就像问题中的屏幕截图一样,你知道为什么IE8在fiddle和本地文件?
-
@EliranMalka 非常感谢您使用 fiddle,我可以分辨出 fiddle html 和我的区别,我使用的是 xml 标头,而 IE8 正确渲染需要
标签: css layout html cross-browser