css - 文档类型和部分

标签 css html layout doctype

我遇到了这个问题,但我不确定为什么会发生......

以下面的 html 为例,它会按照 CSS 的指示显示各个部分的灰色区域。但是,当我包括<!Doctype html>时在第一行它崩溃了..此外,下面的代码根本不适用于 IE9..为什么? 非常感谢。

<html>
<head>

<style type="text/css">
.sec_class{
        width:50%;
        height:15%;
        border:1px black solid;
        padding:0px;
        position:relative;
        background-color:grey;
}
    </style>
</head>

<body>

<section class = 'sec_class'></section>
<section class = 'sec_class'></section>
<section class = 'sec_class'></section>

</body>
</html>

最佳答案

您的部分基本上没有高度,因为以百分比形式给出的高度 (height: 15%;) 将始终为 relative to the parent's height 。在您的情况下,body 的高度为零,而 15% 的高度仍然为零。

这应该有帮助:

html, body { height: 100%; }​

jsFiddle Demo

请务必始终包含文档类型。

关于css - 文档类型和部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10187081/

相关文章:

html - 表格单元格溢出

ListView 的 Android 布局,屏幕底部跟随非滚动文本栏

iPhone 5 屏幕尺寸 VS CSS 媒体查询

css - 有没有办法把一个div放在另一个div后面?

html - 使用 Bootstrap 设置 body 的最大宽度

css - Chrome 开发工具 : Why sometimes a dominating CSS rule is crossed-out?

html - 安全的 Web 文本格式

特定于浏览器的 CSS 样式

html - 使用纯 css 响应移动 View 的背景图像

javascript - 当使用 jqueryeach 将 tr 附加到表 thead 时,结果是空白行