DOCType? It really is important!

While helping a co-worker out with a prolem he was having I learned something very important, always use a DOCType. The problem was with CSS being applied to text inside of a table that was inside a DIV tag, it wasn’t working. But if I applied the style to the table it worked fine. How odd I thought and then spent the next hour trying to find out why this was happening. It turned out that the page ws missing the DOCType declaration. You’ve likely seen it on all kinds of pages waehter they are PHP, plain HTML, or ASP.net.

<DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

The interesting thing about including this DOCType in your page is that it causes browsers (not just IE as some people think) to render in a more standard, and acceptable way. When it’s not there, browsers renders in random ways.

For example, without a DOCType, IE counts the width of the DIV as the content, plus the padding and border width! So suddenly, your 500px DIV is no longer 500px, but 500px minus the width of your border (for each side) and minus the width of your padding.

This entry was posted on Thursday, July 13th, 2006 at 1:03 pm and is filed under Web Design. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

Leave a Reply