gpt4 book ai didi

html - 在 HTML5 中关闭 void 元素时是否还需要正斜杠?

转载 作者:技术小花猫 更新时间:2023-10-29 11:27:31 25 4
gpt4 key购买 nike

在 HTML5 中,我们还需要像 XHTML 中那样的结束斜线吗?

<img src="some_image.png" />

如果我放弃它,validator.w3.org 没有提示,甚至没有警告。但是一些在线文档似乎表明 img, link, meta, br 等标签仍然需要结束斜杠。

最佳答案

在 HTML 5 中,结束斜杠是可选的 void 元素,如 img(我添加这个是因为当前接受的答案只说:“结束标签不能是为 void 元素指定”,并且不解决 void 元素中的结束斜线)。

引自 http://www.w3.org/TR/html5/syntax.html#start-tags (6 号):

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single "/" (U+002F) character. This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

关于html - 在 HTML5 中关闭 void 元素时是否还需要正斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7366344/

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