开发者

Why do browsers render   as a regular space character?

开发者 https://www.devze.com 2023-03-22 13:26 出处:网络
Consider the following HTML snippet: <p>Space&nbsp;Test</p> When this HTML is used in a web page and the page rendered by a browser, the character actually rendered by the browser b

Consider the following HTML snippet:

<p>Space&nbsp;Test</p>

When this HTML is used in a web page and the page rendered by a browser, the character actually rendered by the browser between "Space" and "Test" is a regular space character (U+0020), not a non-breaking space character (U+00A0).

(This can be observed by, for example, using the Firefox extension Character Identifier.)

I tried this in Firefox 5, I开发者_JAVA技巧nternet Explorer 8, and Chrome 12; all had the same behavior of writing out U+0020 instead of U+00A0 on the rendered web page, even though though the source document contained &nbsp; rather than a regular space character.

Why do browsers render a regular space character instead of a non-breaking space character in this way?


This is a relic of pre-Unicode times, when the NBSP character didn't exist in the standard character set. HTML defined the &nbsp; escape sequence as simply a space that shouldn't cause word wrapping.

0

精彩评论

暂无评论...
验证码 换一张
取 消