【发布时间】:2015-04-22 08:55:02
【问题描述】:
这里说http://www.w3.org/TR/html-markup/style.html#style:
允许的父元素
任何可以包含元数据元素的元素,div,noscript, 部分,文章,旁边
<style> 在任何地方都或多或少被允许(允许<div> 的地方)
但是,另一方面,我在这里找到了更详细的信息http://www.w3.org/TR/2012/WD-html5-20121025/the-style-element.html#attr-style-scoped
可以使用该元素的上下文:(注解:style)
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 not as the child of an element whose content model is transparent.
以及本文档后面的内容:
作用域属性是一个布尔属性。如果存在,则表明 样式仅用于以样式为根的子树 元素的父元素,而不是整个 Document。
如果存在作用域属性并且元素有父元素 元素,那么样式元素必须是流内容的第一个节点 在其父元素中,而不是元素间空格,并且 父元素的内容模型不能有透明组件。
这读起来就像有(或将会有)“两个不同的<style> 元素”:一个
-
<style>- 全局 - ~~仅在<head>内 -
<"scopestyle">- 仅(!)具有布尔范围 attr 和 ~~仅在<div>的开头
(请把“~~”读成“或多或少”)
但是后面的链接已经超过 2 年了,所有浏览器(我测试过 Chrome、FF、IE、Opera)都将流入 <style> 解释为好像它在标题中一样。 (并忽略 AFAIK 的范围 - 是的 - 仍然没有标准)
所以我的三部分问题
我对 W3C 文档(两种风格 - 逻辑)的解释是否正确?
现在是什么状态 - 2015 年?
而且,可能有人在那里,谁知道即将发生的事情?
【问题讨论】:
-
如果你导航回w3.org/TR/html-markup,你会发现它已经过时了。由于某种奇怪的原因,通知没有出现在其他任何地方。
-
scoped属性将来可能会重新引入,请参阅:github.com/w3c/csswg-drafts/issues/3547。总之,有一个polyfill。
标签: css html attributes