Skip to: Navigation Content Search


Posts Tagged ‘dtd’

Comments from beyond the DTD Tuesday, August 26th, 2008

According to the W3C validator, it’s ok to place comments above outside your doctype declaration. Like so:

<!-- page last built on October 24, 2007, 21:30 UTC v1.278484 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB">
<head ...

Sure it’s ok. It validates and all is well.

Or is it?

If you, like 90% of web lemmings, have a centred layout courtesy of

#mywrapper {
margin:0 auto;
}

[insert expletive] Internet Explorer 6 will not play ball. This is true for strict, transitional and loose DTDs. It will take your centred layout and crush it like a brick falling on a fresh tuna sandwich.

IE6 either ignores that specific CSS rule or pushes your container div to the left on purpose (I haven’t worked out exactly which). Everything else will look as normal.

Taking out these comments or moving them underneath the doctype declaration will fix it of course. I suppose it’s not surprising that the document syntax rules should really be the first element to appear in the document, but IE’s specific behaviour is still inexplicable.

* Update: Thanks to Scott G for his common sense. ie6 seems to go into quirks mode when comments are placed above the DTD. Taking out the comments and the DTD all together, or leaving in the comments and removing the DTD, cause the browser to behave in the same manner.

* Proposal: start a campaign of ridicule and intimidation targeting anyone still using ie6. Update 13th of November 2008: someone has beat us to it!