HTML 5:是 <br>、<br/> 还是 <br/>? [英] HTML 5: Is it <br>, <br/>, or <br />?
问题描述
我试过查看).
现在我想知道在练习 HTML 5 时我应该如何格式化我的代码.
是
、
还是
?
只需
就足够了.
其他形式是为了与 XHTML 兼容;使编写与 XHTML 相同的代码成为可能,并使其也作为 HTML 工作.一些生成 HTML 的系统可能基于 XML 生成器,因此无法仅输出一个裸露的 <br>
标签;如果你在使用这样的系统,使用<br/>
就可以了,如果你不需要的话就没有必要了.
然而,很少有人真正使用 XHTML.您需要将您的内容作为 application/xhtml+xml
提供,以便将其解释为 XHTML,这在旧版本的 IE 中不起作用 - 这也意味着您犯的任何小错误都会阻止您的页面不会在支持 XHTML 的浏览器中显示.因此,Web 上大部分看起来像 XHTML 的内容实际上是作为 HTML 提供和解释的.有关更多信息,请参阅将 XHTML 视为有害的文本/html.
I've tried checking other answers, but I'm still confused — especially after seeing W3schools HTML 5 reference.
I thought HTML 4.01 was supposed to "allow" single-tags to just be <img>
and <br>
. Then XHTML came along with <img />
and <br />
(where someone said that the space is there for older browsers).
Now I'm wondering how I'm supposed to format my code when practicing HTML 5.
Is it <br>
, <br/>
or <br />
?
Simply <br>
is sufficient.
The other forms are there for compatibility with XHTML; to make it possible to write the same code as XHTML, and have it also work as HTML. Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare <br>
tag; if you're using such a system, it's fine to use <br/>
, it's just not necessary if you don't need to do it.
Very few people actually use XHTML, however. You need to serve your content as application/xhtml+xml
for it to be interpreted as XHTML, and that will not work in old versions of IE - it will also mean that any small error you make will prevent your page from being displayed in browsers that do support XHTML. So, most of what looks like XHTML on the web is actually being served, and interpreted, as HTML. See Serving XHTML as text/html Considered Harmful for some more information.
这篇关于HTML 5:是 <br>、<br/> 还是 <br/>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!