HTML中的右尖括号 [英] Right angle bracket in HTML

查看:439
本文介绍了HTML中的右尖括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于显而易见的原因,左尖括号不能在HTML文本中直接使用。右尖括号的状态并不十分清楚。它在我尝试时可以正常工作,但当然浏览器对于不是严格有效的HTML格式的构造而言是众所周知的宽容。

http://www.w3.org/TR/html4/charset.html#h-5.4 似乎是说它是有效的,虽然可能不被旧版本的浏览器支持,但也特别提到了引用的属性值。 是否需要html编码右尖括号?还说这是有效的,但是再次具体谈到引用的属性值。

简单的文本块(< pre> 元素碰巧就是这种情况),并且它有什么不同?

解决方案

<>可以使用字符>作为任何版本的HTML中的数据字符,既可以在元素内容中,也可以在属性值中使用。这是因为在规范中没有任何相反的声明。

它经常被转义为& gt; ,这是有效的,但不是任何正式或技术原因所必需的。部分原因是人们认为它需要与<字符需要转义相同的方式,部分原因是为了对称:例如,编写& lt; code& gt; 可能看起来比< code> 更对称。



字符>是比那更大的字符。在许多情况下,如HTML标记,用作一种类似的分隔符,用类似括号的方式,但在一些数学符号中使用的实际尖括号是相当不同的,例如⟩U + 27E9 。如果您需要在HTML文档中包含尖括号,则需要考虑一些严重问题,但它们与字体(和语义)相关,而不是与标记重要字符的任何潜在冲突。


For obvious reasons, the left angle bracket cannot be used literally in HTML text. The status of the right angle bracket is not quite so clear. It does work when I try it, but of course browsers are notoriously forgiving of constructs that are not strictly valid HTML.

http://www.w3.org/TR/html4/charset.html#h-5.4 seems to be saying it's valid, though may not be supported by older browsers, but also makes specific mention of quoted attribute values. Is it necessary to html encode right angle brackets? also says it's valid but again specifically talks about quoted attribute values.

What's the answer for plain chunks of text (contents of a <pre> Element happens to be the case I'm looking at), and does it differ in any way?

解决方案

The character ">" can be used as such as data character in any version of HTML, both in element content and in an attribute value. This follows from the lack of any statement to the contrary in the specifications.

It is often routinely escaped as &gt;, which is valid but not required for any formal or technical reason. It is used partly because people assume it is needed the same way as the "<" character needs to be escaped, partly for symmetry: writing, say, &lt;code&gt; may look more symmetric than &lt;code>.

The character ">" is the GREATER THAN character. It is used in many contexts, like HTML markup, as a delimiter of a kind, in a bracket-like manner, but the real angle brackets, as used in some mathematical notations, are rather different, such as "⟩" U+27E9. If you need to include angle brackets in an HTML document, you have some serious issues to consider, but they relate to fonts (and semantics), not to any potential clash with markup-significant characters.

这篇关于HTML中的右尖括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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