为什么<br/>而不是 <br/>? [英] why <br /> and not <br/>?
问题描述
这是你读过一次的东西之一,说啊哈!"然后忘记.正是我的情况.
This is one of those things that you read once, say "aha!" and then forget. Exactly my case.
为什么xhtml中的换行标签优先用空格<br/>
而不是也可以的格式<br/>
?我记得原因很有趣,你可以想象,用谷歌搜索并不容易.
Why is the line-break tag in xhtml preferentially written with a space <br />
and not in the also ok format <br/>
? I remember the reason was interesting, and as you can imagine it's not easy to find with google.
当然,这不是 xml 格式正确的问题.来自 W3C
For sure it's not an issue of xml well-formedness. From W3C
[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
Empty-element tags may be used for any element which has no content, whether
or not it is declared using the keyword EMPTY. For interoperability, the
empty-element tag should be used, and should only be used, for elements which
are declared EMPTY.
Examples of empty elements:
<IMG align="left" src="http://www.w3.org/Icons/WWW/w3c_home" />
<br></br>
<br/>
所以末尾的空格是可选的.
So the space at the end is optional.
推荐答案
如果我没记错的话,这仅仅是因为一些较旧的浏览器在使用斜线前没有空格的自关闭标签方面存在问题.我现在怀疑这是一个问题,但很多开发者(包括我自己)都养成了包含空间的习惯.
If I recall correctly it's simply because some older browsers had problems with a self-closing tag without a space before the slash. I doubt it's an issue nowadays, but a lot of developers (myself included) got into the habit of including the space.
啊,我们到了:
http://www.w3.org/TR/xhtml1/#guidelines
在空元素的尾随/和 > 之前包含一个空格,例如<br/>
, <hr/>
和 <img src="karen.jpg" alt="Karen"/>代码>.此外,对空元素使用最小化的标签语法,例如
<br/>
,作为 XML 允许的替代语法 <br></br>
在许多现有的用户代理中给出了不确定的结果.
Include a space before the trailing / and > of empty elements, e.g.
<br />
,<hr />
and<img src="karen.jpg" alt="Karen" />
. Also, use the minimized tag syntax for empty elements, e.g.<br />
, as the alternative syntax<br></br>
allowed by XML gives uncertain results in many existing user agents.
这篇关于为什么<br/>而不是 <br/>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!