微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xhtml – 为什么而不是?

这是你读过的一件事,说“哈哈!”然后忘记。完全是我的情况

为什么xhtml中的line-break标签优先用空格< br />而不是格式为& br /> ?我记得这个原因很有趣,而且你可以想象,用google找到并不容易。

当然,这不是xml良好的问题。来自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/>

所以最后的空间是可选的。

解决方法

如果我记得正确,这只是因为一些旧的浏览器在斜线之前没有空格的自动关闭标签有问题。我怀疑这是现在的问题,但很多开发者(包括我自己)都习惯了包容空间。

编辑:啊,这里我们是:

http://www.w3.org/TR/xhtml1/#guidelines

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,as the alternative Syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

原文地址:https://www.jb51.cc/html/233414.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐