the blank space below the <body> tag & script tag and link tag goes under body tag from head tag
I wrote a php app using php+smarty.
When I view the web source code in firebug, I find that link tag and script tag get under the body tag. But it should be under the head tag.
And there are some space below body tag.
And there is blank space on my top of my web page.
What is the proble开发者_如何转开发m?
You've got some stray text content inside the <head>
, before the <link>
tag. The browser sees the text and decides this means you're starting the main document body but have forgotten to include the <body>
tag.
This is actually valid—if inadvisable—in HTML4: the <head>
end-tag and <body>
start-tag are both optional. This is how you can have just <html><head><title>x</title>Hello!
as a valid HTML document. But it's not permissible in XHTML, so if you validate your document you should get a “character data is not allowed here” error at the point the stray text occurs.
The browser then parses the rest of the document as body content, putting the <link>
inside the body (which is not valid, but which is nonetheless commonplace). It ignores the real <body>
when that comes along because it already has a body.
If you can't see the stray text, perhaps it's an invisible character like U+00A0 No-break space
or—most likely for Chinese documents—U+3000 Ideographic space
, which you may get when you press space in some input method modes. These characters won't be visible, but they're not ‘ignorable whitespace’ like a normal U+0020 Space or newline, so they trigger ‘text content’ processing and force the <body>
.
Blank spaces, specially at the start of the webpage are usually caused because the file is saved in the format UTF-8 (which contains BOM). If you are using an editor like Notepad++ or Vim, save the file in the format UTF-8 without BOM.
Add the following CSS:
html, body
{
padding: 0px;
margin: 0px;
}
Send your HTML through a validator ( http://validator.w3.org/ ) - it'll tell you what kind of error you've got in there (missing closing tag or something).
精彩评论