views:

66

answers:

3

alt text

alt text

hey guys, i wrote a php app using php+smarty.

when i view web source code in firebug, i find that link tag and script tag get under the body tag. but i should be under head tag.

and there are some space below body tag.

and there's blank space on my top of my web page.

so , what's the problem?

A: 

Add the following CSS:

html, body
{
    padding: 0px;
    margin: 0px;
}
Gazler
i've tried this,nothing changed. it seems that's not the problem of CSS.
tunpishuang
as a matter of fact, i always start my layouts with * { margin: 0px; padding 0px } :D
Joe Hopfgartner
Instead of a botch reset job like `*{margin:0;padding:0}` you really ought to be using a proper reset CSS file. There's a few out there :)
chigley
+2  A: 

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>.

bobince
i think that's the point , so how do i correct the error. after searching the web,they say maybe it's the problem of UTF-8 with BOM.
tunpishuang
Although putting a faux-BOM at the start of a UTF-8 file is a Microsoft-inspired wrongness that should be avoided, it won't be the problem here: web browsers all ignore the BOM. The text in question is inside the `<head>`, between the `<title>` and the `<link>`. Validate your page as XHTML and the validator will highlight the incorrect text with an error. If it is a problem with the full-width space character ` `, best do a global replace with a normal space, because it can cause problems like gaps in other places too.
bobince
W3C markup Validator show the message:"Byte-Order Mark found in UTF-8 File.The Unicode Byte-Order Mark (BOM) in UTF-8 encoded files is known to cause problems for some text editors and older browsers. You may want to consider avoiding its use until it is better supported. "
tunpishuang
Yeah, it's a sensible warning and you should definitely get rid of the fake-BOM (save in your text editor as UTF-8-without-BOM), but it's not the cause of your problem here.
bobince
@bobince , Please check ur email box.i've send you the sample document.
tunpishuang
The file you sent doesn't have any stray text and does not exhibit this behaviour (ending the `<head>` before `<link>` and consequently causing the gap) for me. It's not clear to me how the template could end up adding anything between the `</title>` and the `<link>`, either. What does the .html output look like?
bobince
@bobince , i've found the answer!!!
tunpishuang
@bobince the reason is that i'm using require_once() function of php in my index.php (index page handle script) include some class and library php file. these php file were using utf-8 with bom code. so the stray text appeared once i include one of these php files. And i view these files in hex mode , every file starts with EF BB BF which is the content of the stray text. LOL. also thx bobince for your clue.
tunpishuang
Ah! Another include *inside* the `<head>`... yes, that would certainly do that. Man, I hate Microsoft's determination to drop faux-BOM turdlets by default in UTF-8 output.
bobince
A: 

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).

DanMan