为什么<br/>而不是<br/>? [英] why <br /> and not <br/>?

查看:25
本文介绍了为什么<br/>而不是<br/>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是你读过一次的东西之一,说啊哈!"然后忘记.正是我的情况.

This is one of those things that you read once, say "aha!" and then forget. Exactly my case.

为什么xhtml中的换行标签优先写成空格<br/>而不是也ok的格式<br/>?我记得原因很有趣,你可以想象用 google 很难找到.

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.

这篇关于为什么&lt;br/&gt;而不是&lt;br/&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆