对于div使用单个标签有效吗? [英] Is it valid HTML5 to use a single tag for a div?
问题描述
例如:< div />
,而不是< div>< / div>
。
我这样做了,显然HTML5验证器通过了这个验证。我想知道这实际上是真的吗?
For example: <div/>
instead of <div></div>
.
I did this and apparently the HTML5 validator passed this as valid. I was wondering it this is actually true?
PS:我将页面作为application / xhtml + xml提供服务
PS: I'm serving page as application/xhtml+xml
div $ ht_lin>解决方案
c $ c>标签)。这是有效的XHTML 5,因为它是有效的XML。
This is not valid HTML 5 (HTML does not allow shorttags, the equivalent HTML construct is a single opening div
tag). It is valid XHTML 5, as it is valid XML.
您可能会看到通过验证器的原因很好,因为您说过:
The reason why you might see this pass through a validator just fine is because of what you stated:
PS:我将页面作为application / xhtml + xml提供服务
PS: I'm serving page as application/xhtml+xml
这意味着您告诉验证程序必须将您的标记视为XML。换句话说,您的网页完全不是HTML 5。
Which means that you tell the validator that it must treat your markup as XML. In other words your page is not HTML 5 at all.
这篇关于对于div使用单个标签有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!