html - IE8 文档类型声明的 100% 高度问题

标签 html css xhtml internet-explorer-8

好的,我有一个简单的 HTML 网页。问题是,当我在页面开头指定 Doctype 时,我的样式表 height:100% 不起作用。

如果我删除文档类型声明,一切都会按预期进行。所以有人知道为什么会这样吗?我应该使用什么文档类型?
我也尝试使用“严格”DOCTYPE 声明,但仍然存在同样的问题。 提前致谢。

下面是完整的 HTML,其中 height:100% 不起作用:

<!DOCTYPE html PUBLIC "-//VYOM//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/transitional.dtd">
<html>     
<body>
    <div style="background-color:red; height:100%;">
        testing 123...
    </div>     
</body>

如果我删除文档类型,DIV 会按预期占用 100% 的可用高度:

<html>     
<body>
    <div style="background-color:red; height:100%;">
        testing 123...
    </div>     
</body>
</html>

最佳答案

添加:

body, html {
    height:100%
}

关于html - IE8 文档类型声明的 100% 高度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7837116/

相关文章:

php - Html 外文字符编码

html - flex 和溢出 : weird behaviour

xhtml - 符合 XHTML 的意义何在?

html - 当我在 chrome 开发工具中点击切换设备时,我不能让容器响应

javascript - 通过组合变量对多个输入字段进行表单验证

html - 拉伸(stretch)图像

css - 如何设置 "placeholder"文本的颜色?

CSS3 选择器 - 选择第一个元素或之后的元素

css - FF/Chrome 中奇怪的表对齐行为

html - 如何为 HTML 页面创建渐变背景