<h2 section>foobar</h2>
而不是:< h2 section =“”> foobar< / h2>
这两个片段同样有效吗?如果没有,它们是否在HTML版本5中有效?
谢谢!
解决方法
From W3C:(在SGML和HTML上)
Some attributes play the role of boolean variables (e.g.,the selected
attribute for theOPTION
element). Their appearance in the start tag
of an element implies that the value of the attribute is “true”. Their
absence implies a value of “false”.Boolean attributes may legally take a single value: the name of the
attribute itself (e.g.,selected="selected"
).
这表明布尔属性在HTML4中也是有效的,但是如果你使用类似的东西,则会无效..因为布尔值属于选项标签..感谢@Ronni Skansing澄清疑问..
<p selected>Hello</p>
HTML5文档:
空属性语法
Certain attributes may be specified by providing just the attribute
name,with no value.
From W3C:(每晚HTML 5.1)
A number of attributes are boolean attributes. The presence of a
boolean attribute on an element represents the true value,and the
absence of the attribute represents the false value.
但
section是一个无效的属性,如果你想定义自己的属性,HTML5提供了一种方法来做到这一点..你需要使用data-
前缀,例如,你的节应该写成数据节,这样你的属性将是算作有效.
如果您犹豫不决,我们总会有一个验证员来检查 – W3C Markup Validation Service
^验证为HTML5
NOTE: Though I provided
data-
is applicable for HTML5,using custom
attributes in HTML4 is invalid,no matter even if you definedata-
before the attribute name,but,boolean attributes are valid in HTML4 as well.