HTML:BR 的正确形式是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4288460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML: What's the correct form of BR?
提问by Adam
How is correct to write the br
tag in html
?
如何正确写入br
标签html
?
<br />
or
或者
<br>
or anything else? :))
还是别的什么?:))
回答by casablanca
It depends on the doctype you're using. In the original versions of HTML (up to HTML4), only <br>
is correct. In XHTML (which is based on XML), only <br />
is correct. In HTML5, both are allowed although <br>
is preferred.
这取决于您使用的文档类型。在 HTML 的原始版本(最高为 HTML4)中,只有<br>
是正确的。在 XHTML(基于 XML)中,只有<br />
是正确的。在 HTML5 中,虽然<br>
是首选,但两者都是允许的。
回答by pyvi
It does not need an end tag, so
它不需要结束标签,所以
<br>
is correct for HTML, and
对 HTML 是正确的,并且
<br />
for XHTML.
对于 XHTML。
回答by Jon Hanna
In HTML4.01 or earlier, it is <br>
. This is case-insensitive, and whitespace between the r
and the >
is ignored.
在 HTML4.01 或更早版本中,它是<br>
. 这是不区分大小写,并且空格之间r
和>
被忽略。
In all forms of XHTML it is <br/>
. This is case-sensitive, and again whitespace between the r
and the />
is ignored. <br></br>
is also allowed, but unusual (there are backwards-compatibility issues, it's extra typing, and allows for bugs if you introduce more content between the tags by mistake, but it does sometimes happen in XML-programattically produced code).
在所有形式的 XHTML 中,它都是<br/>
. 这是区分大小写的,并且再次忽略r
和之间的空格/>
。<br></br>
也是允许的,但不寻常(有向后兼容性问题,它是额外的输入,如果您错误地在标签之间引入更多内容,则允许出现错误,但它有时会发生在以 XML 编程方式生成的代码中)。
Since some earlier browsers that would parse XHTML as earlier HTML would choke on <br/>
but not on <br />
such extra whitespace is the norm, for backwards compatibility (more backwards kludging it, but still...).
由于一些早期的浏览器将 XHTML 解析为早期的 HTML 会阻塞<br/>
但不会阻塞在<br />
这种额外的空白处是常态,为了向后兼容(向后兼容它,但仍然......)。
In HTML5 either are allowed (but not <br></br>
).
在 HTML5 中,两者都允许(但不允许<br></br>
)。
回答by stealthyninja
@CIRK: HTML4, <br>
. XHTML 1.x, <br />
. <br/>
is also acceptable.
@CIRK:HTML4, <br>
。XHTML 1.x, <br />
. <br/>
也是可以接受的。
回答by Marcos Roriz Junior
You should use <br />
because it respect the standards XHTML, HTML and in general (XML). Because every xml tag needs to close.
您应该使用<br />
它,因为它遵守 XHTML、HTML 和一般 (XML) 标准。因为每个 xml 标签都需要关闭。
回答by ryryan
In HTML (up to version 4) it's <br>
And in XHTML it's <br />
because the tag has to be properly closed with an /
在 HTML(直到第 4 版)中是,<br>
而在 XHTML 中,这是<br />
因为标签必须用 / 正确关闭
HTML5 <br>
is the best option.
HTML5<br>
是最好的选择。
回答by demas
<br/>.
Some of the most common errors in the usage of XHTML are:
Not closing empty elements (elements without closing tags in HTML4)
Incorrect: <br>
Correct: <br />
Note that any of these is acceptable in XHTML: <br></br>, <br/>, and <br />. Older HTML-only browsers interpreting it as HTML will generally accept <br> and <br />.
回答by Randy
it is most formal to use <br/>
this is then XHTML compliant - all opening tags have corresponding end tag.
最正式的使用方式<br/>
是 XHTML 兼容 - 所有开始标签都有相应的结束标签。