Http://w3help.org/zh-cn/causes/HG8001
Standard Reference
As mentioned in the HTML 4.01 standard, a blank character is allowed before or after the DTD. The "blank character" mentioned here includesSpace Character,Line Break,TabAndNote.
For details about the structure of HTML documents, refer to the content in HTML 4.01 standard 7.1 Introduction to the structure of an HTML document.
Problem description
If you add comments or other content before a DTD, The DTD cannot be recognized in some browsers.
Impact
This problem will cause the same page to work in some browsers in standard mode (S) and other browsers to work in hybrid mode (Q, as a result, the performance of the page varies greatly in various browsers, such as layout disorder, overlapping content, and unavailability of functions.
Affected browsers
IE6
Any non-blank characters before the DTD will make the browser ignore the DTD, including comments and XML declarations.
IE7 IE8
Any non-blank characters before the DTD will cause the browser to ignore the DTD, including comments, but not XML declarations.
Firefox
Any character that contains "<" before the DTD will make the browser ignore the DTD, but does not include the XML declaration.
Chrome Safari Opera
Any non-blank characters before the DTD will make the browser ignore the DTD, but do not include the XML declaration.
Problem Analysis
If other characters appear before the DTD of an HTML document, the processing conditions in different browsers are inconsistent.
For specific differences, see the following table:
If
Can the browser recognize this DTD?
[Note]
1. HTML comments, such as <! -- Comment -->.
2. Similar to <? Xml version = "1.0" encoding = "UTF-8"?> .
3. It is not a space character, line break, or Tab character, nor any other string declared by comments or XML, but cannot contain the "<" character.
4. It is not a space character, line break, or Tab character, or any other string declared by comments or XML, including the "<" character.
Through the comparison above, we can see that to ensure that the DTD can be properly recognized in all browsers, it can only appear beforeSpace Character,Line BreakAndTab.
Solution
When declaring a DTD, make sure that the DTD has no other characters.Space Character,Line BreakAndTab.
For example, place the DTD In the first line of the HTML document.