我遇到了这个问题,但我不确定为什么会发生......
以下面的 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%; }
请务必始终包含文档类型。
关于css - 文档类型和部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10187081/