1

问候大家,

我想知道是否有人注意到这种不一致并知道如何解决它。

示例:http: //jsfiddle.net/p5G2N/

前提:

多个单词由未编码的 & 符号连接;没有空格。

<p>Goodevening&goodnight</p>

结果:

Chrome/IE:无法将字符解释为 & 符号,从而破坏了预期的大写样式。显示为:Goodevening&Goodnight [不正确 - 注意晚安的大写 G,因为它是一个单词,所以不应该大写]

Firefox:设法正确解释未编码的&符号并将字符串视为单个单词。显示为:晚安和晚安[正确]

问题:

如何让 Chrome/IE 尊重样式(大写)?

4

3 回答 3

3

&amp 应该用过&。从W3 规范

作者应该使用"&amp;"(ASCII decimal 38) 而不是"&"避免与字符引用的开头混淆(实体引用打开分隔符)。作者还应该"&amp;"在属性值中使用,因为在 CDATA 属性值中允许字符引用。

于 2013-03-05T16:11:57.117 回答
2

TL;DR: Your expectation is incorrect. goodbye&goodnight has two word-separation points, one on each side of the ampersand. Whether the ampersand is encoded or not is irrelevant.


As far as I know, CSS doesn't fully specify what a "word" is, but there is a recommendation to use the Unicode standard word separation algorithm, which you can find here (UAX29).

An informal summary is that a word is a sequence of letters, numbers or "Connector_Punctuation" symbols (ties), and possibly containing "MidLetter", "MidNum" or "MidNumLet" symbols (there's a list in the referenced document), depending on the immediate context of the symbol. & is not in any of those categories, so a UAX29-conformant word-separation algorithm should split words before and after an &.

A word separation algorithm may take language into account. Indeed, it may do just about anything, but it's supposed to be unsurprising for a native speaker of the language. Non-programmers would probably be surprised if word&word were considered one word.

于 2013-03-05T16:38:50.983 回答
0

如果要&在 HTML 中使用 - 符号,请&amp;改用。

于 2013-03-05T16:10:26.850 回答