Please take a look at this image:
On the top left, notice how HelloWorld
does not have a space between them, while Foo Bar
does. The right side shows the mark up; there is no space after Foo
or before Bar
; just a carriage return and a few tabs. The bottom left shows what the DOM is (per Firebug).
Question: what is there a space between Foo
and Bar
?
NOTE: here it is on JSFiddle, but it seems to have converted the tabs into spaces: http://jsfiddle.net/sM6rk/
Original mark up (again, tabs turned into spaces):
<html>
<head>
</head>
开发者_运维问答 <body>
<p>Hello<em>World</em></p>
<p>Foo
<em>Bar</em>
</p>
</body>
</html>
The CSS spec explains the presentation of the white-space processing model, specifically:
- [..snip..]
- [..snip..]
- If 'white-space' is set to 'normal' or 'nowrap', linefeed characters are transformed for rendering purpose into one of the following characters: a space character, a zero width space character (U+200B), or no character (i.e., not rendered), according to UA-specific algorithms based on the content script.
- If 'white-space' is set to 'normal', 'nowrap', or 'pre-line', every tab (U+0009) is converted to a space (U+0020) any space (U+0020) following another space (U+0020) — even a space before the inline, if that space also has 'white-space' set to 'normal', 'nowrap' or 'pre-line' — is removed.
In HTML, all whitespace is converted into a single space (or whatever equivalent for the language) unless it is within a block marked as preserve-whitespace
. This includes spaces, tabs, and newlines.
For more specific details, please see The HTML 4.01 spec.
Yes, all white space characters are interpreted as spaces, and multiple white space characters are interpreted as a single space.
So, the newline and spaces between Foo and Bar is interpreted as a single space.
精彩评论