XHTML 标签在 HTML 中有效吗?
据我所知,HTML 中的换行符是
,而 XHTML 中的换行符是
。
我知道您不能在 XHTML 文档中使用上述 HTML 标记,但反之亦然呢?
在 HTML 中有效吗?
I understand a line break in HTML is <br>
and the XHTML equivalent is <br />
.
I know that you cannot use the above HTML tag in a XHTML document, but what about vice versa? Is <br />
valid in HTML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这取决于您所讨论的 HTML 版本。
在最新的稳定版本HTML 4.01中,语法含义相同为
,其含义与>
相同。这意味着它是有效的,因为您可以在任何可以换行的地方使用>
>
(尽管通常无效),但是并不意味着你想要什么。浏览器的限制(由 XHTML 1.0 规范利用)意味着它会被视为
,即使它不应该如此。此功能的混乱意味着它被标记为要避免。HTML 5 改变了这一点 并将
/ 转换成语法糖。完全没有意义,但允许,所以 XML 迷们很高兴。
It depends which version of HTML you are talking about.
In the latest stable version, HTML 4.01, the syntax means the same as
<br>>
which means the same as<br>>
. This means it is valid, since you can have a>
anywhere you can have a line break, (although<meta />
usually isn't valid) but doesn't mean what you want. Limitations in browsers (exploited by the XHTML 1.0 spec) mean that it gets treated as<br>
even though it shouldn't be. The mess around this feature means it is marked as to be avoided.HTML 5 changes that and turns the
/
into syntactic sugar. Utterly meaningless but allowed so the XML junkies are kept happy.
向后兼容,如果在 HTML 文档中使用,不会导致渲染问题。另请注意,除非您使用 MIME 类型
application/xhtml+xml
提供文档,否则将
放入 XHTML 文档中不会导致它呛。在 XHTML 文档中留下 BR 未关闭是一种验证错误,但这是一个非常小的错误,本身不太可能导致任何问题。编辑:哦,是的,在 HTML5 中,结束
/
再次正式可选。<br />
is backwards compatible and will not cause rendering problems if used in an HTML document.Also, note that unless you are serving your documents with the MIME type
application/xhtml+xml
, putting a<br>
in an XHTML document won't cause it to choke. It is a validation error to leave a BR unclosed in an XHTML document, but a very minor one which is unlikely to cause any problems by itself.EDIT: Oh yes, and in HTML5 the closing
/
is once again officially optional.
是有效的 HTML。某些 HTML 页面可能是由无法输出
的 XML 引擎生成的,因此它必须能够解析它。<br />
is valid HTML. Some HTML pages may be generated by an XML engine that can't outpout<br>
, and as such it must be able to parse it.是的,XHTML 与 HTML 兼容。
我相信 HTML5 中有一个例外,即像
这样的处理指令已被弃用。
Yes XHTML is compatible with HTML.
I believe there is one exception in HTML5 which is processing instructions like
<?xml...>
have been deprecated.