无法解决正文中的样式标签验证问题

Not able to solve the style tag validation issue in body

我收到以下 HTML 验证错误:

Element style not allowed as child of element div in this context. (Suppressing further errors from this subtree.)

我在 style 标签上使用了 HTML 5.1 中的 scoped 属性:

<style scoped>

知道根本原因是什么吗?

根本原因是这样的:

The scoped attribute has been removed from the specification after only limited and experimental adoption by Chrome and Firefox.

浏览器支持如下:

  • 通过在 chrome://flags 中启用 "Enable " 或 "experimental WebKit features" 标志,在 Chrome 20+ 到 34 中受支持。由于代码复杂,已在 Chrome 35+ 中删除。

  • Gecko 20 及更高版本实现 :scope pseudo-class,但首选项 layout.css.scope-pseudo.enabled 必须设置为 true。这只是 Nightly 和 Aurora 测试版中默认的情况。

参考资料