【发布时间】:2015-02-16 19:08:56
【问题描述】:
<!DOCTYPE html>
...
<style scoped>
/* css */
</style>
w3.org 验证器给我这个错误:
Line 883, Column 17: Element style not allowed as child of element body in this context.
(Suppressing further errors from this subtree.)
<style scoped>...
Contexts in which element style may be used:
If the scoped attribute is absent: where metadata content is expected.
If the scoped attribute is absent: in a noscript element that is a child of a head element.
If the scoped attribute is present: where flow content is expected, but before any other flow content other than inter-element whitespace and style elements, and not as the child of an element whose content model is transparent.
Content model for element body:
Flow content.
据我了解,'scoped' 属性使得样式标签可以位于文档头部之外。那么为什么验证者对此不满意呢?
(我使用的是 Wordpress,这段代码是由插件生成的,这就是为什么我不能把它放在头上。)
编辑: 这不验证 -
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<script type="text/javascript"></script>
<style scoped></style>
</body>
</html>
但如果脚本标签在样式标签之后,它会这样做。这是什么原因?
【问题讨论】:
标签: html css w3c-validation