我正在尝试制作 100% 高度的东西,但添加文档类型会破坏它。这在 other questions 上进行了解释. 然而,我发现了一些奇怪的事情——如果我关闭 doctype 标签(我知道你不应该这样做)然后 100% 高度在 chrome 和 IE 上再次工作。那么到底发生了什么?关闭文档类型是否意味着文档类型被忽略?
<!doctype html/> <!--You're not supposed to close doctype but if you do, then
the 100% sizing works. Why?-->
<html>
<body>
<!--This 100% height won't work with a normal doctype but closing
the doctype makes it work?-->
<div style="border:5px solid black;height:100%">This should be 100%</div>
</body>
</html>
最佳答案
根据 8.1.1 The DOCTYPE ,
A DOCTYPE must consist of the following components, in this order:
- A string that is an ASCII case-insensitive match for the string "
- One or more space characters.
- A string that is an ASCII case-insensitive match for the string "html".
- Optionally, a DOCTYPE legacy string or an obsolete permitted DOCTYPE string (defined below).
- Zero or more space characters.
- A ">" (U+003E) character.
因此,您的“封闭文档类型”是无效的文档类型。因此就像您根本没有文档类型一样。
关于css - doctype 会 100% 杀死但如果 doctype 关闭则不会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32447412/