tags:

views:

70

answers:

4

is it possible to use DOCTYPE tag in line 2 or 3 or ... and css works good ? (not line 1)

tag :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
A: 

by standards, the DOCTYPE should be the first line. why would you not want to put it there anyways?

GSto
I've designed a blog template and the blog service add force advertising code in first line and my templates css not works good
lashX
+1  A: 

Seems like you are very persistent about doing strange things with your doctype. It's best you always use it AND put it on the first line of your document. If you go arround the web you'll find that almost every website has it like that.

Is there a reason why you don't want to do so?

J. Vermeire
I've designed a blog template and the blog service add force advertising code in first line and my templates css not works good!
lashX
Maybe you should consider hosting your blog yourself then. Forcing their code in your template isn't very nice of them :(
J. Vermeire
This won't work. It does have to come before the document itself.
jcdyer
Worst hosting service ever! If a service inserts code at the very start of your page, then you will never be able to make a valid page, and you'll be stuck in horrible Quirks Mode, breaking your CSS. Give them the boot!
bobince
+1  A: 

Yes. As long as it comes before your <html> tag, you should be fine. This might happen, for instance, if you put an XML declaration above it. The xml declaration, however, must occur at the very beginning of the file.

Example:

<?xml version='1.0' charset='utf-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html>
  <head>
    <title>This is an example</title>
  </head>
  <body>
    <h1>This is an example</h1>
    <p>
      You might even put an xml stylesheet declaration up above your 
      DTD declaration, which would look like this: 
      <code>&lt;?xml-stylesheet type="text/xsl" href="transform.xsl"?&gt;</code>
    </p>
    <p>But you still can't put any HTML above your DOCTYPE.  Sorry.</p>
  </body>
</html>
jcdyer
plz give me an example
lashX
Avoid including an `<?xml` declaration if you are producing XML *for web browsers*. If you're producing xml for other contexts, you should include it. If you are using xml version 1.1, you have to include it.
jcdyer
+1  A: 

IE6 will fall into quirks mode if you put anything (including an XML declaration) before the Doctype. So - "no".

Most browsers will fall into quirks mode (AFAIK) if any content appears before it. Don't use hosts who prevent you from using valid markup.

David Dorward