gpt4 book ai didi

html - XHTML 中所有有效的自闭合元素(由主要浏览器实现)是什么?

转载 作者:IT老高 更新时间:2023-10-28 11:06:50 25 4
gpt4 key购买 nike

XHTML 中所有有效的自闭合元素(例如
)(由主流浏览器实现)是什么?

我知道 XHTML 在技术上允许任何元素自封闭,但我正在寻找所有主要浏览器支持的那些元素的列表。见 http://dusan.fora.si/blog/self-closing-tags

等自闭合元素引起的一些问题为例。

最佳答案

每个支持 XHTML 的浏览器(Firefox、Opera、Safari、IE9)都支持每个元素上的自闭合语法。

<div/> , <script/> , <br></br>一切都应该正常工作。如果没有,那么您的 HTML 中添加了不当的 XHTML DOCTYPE。

DOCTYPE 不会改变文档的解释方式。 Only MIME type does

W3C decision about ignoring DOCTYPE :

The HTML WG has discussed this issue: the intention was to allow old(HTML-only) browsers to accept XHTML 1.0 documents by following theguidelines, and serving them as text/html. Therefore, documents served astext/html should be treated as HTML and not as XHTML.

这是一个非常常见的陷阱,因为 W3C Validator 在很大程度上忽略了该规则,但浏览器却虔诚地遵循它。读 Understanding HTML, XML and XHTML来自 WebKit 博客:

In fact, the vast majority of supposedly XHTML documents on the internet are served as text/html. Which means they are not XHTML at all, but actually invalid HTML that’s getting by on the error handling of HTML parsers. All those “Valid XHTML 1.0!” links on the web are really saying “Invalid HTML 4.01!”.


要使用 XHTML 的 DOCTYPE 测试您是否有真正的 XHTML 或无效的 HTML,请将其放入您的文档中:

<span style="color:green"><span style="color:red"/> 
If it's red, it's HTML. Green is XHTML.
</span>

它会验证,并且在真正的 XHTML 中它可以完美运行(参见:12 )。如果您不相信自己的眼睛(或不知道如何设置 MIME 类型),请通过 XHTML proxy 打开您的页面.

另一种检查方法是在 Firefox 中查看源代码。当斜线无效时,它将以红色突出显示。

在 HTML5/XHTML5 中这并没有改变,而且区别更加清晰,因为你甚至没有额外的 DOCTYPE . Content-Type是国王。


作为记录,XHTML 规范允许任何元素通过将 XHTML 设为 XML application 来自动关闭。 : [强调我的]

Empty-element tags may be used for any element which has no content, whether or not it is declared using the keyword EMPTY.

它也在 XHTML spec 中明确显示:

Empty elements must either have an end tag or the start tag must end with />. For instance, <br/> or <hr></hr>

关于html - XHTML 中所有有效的自闭合元素(由主要浏览器实现)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/97522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com