Skip to content

Importance of Doctypes and browser behaviour

February 18, 2007

I was trying to center a DIV today and couldn’t figure out why it wasn’t working as expected in IE7.
To center a DIV, you can use CSS and set the margin-left, margin-right to auto and give the DIV a fixed width. However, a bug in IE6 required that you also set the text-align of the body to center.

I noticed that http://www.textdrive.com/ homepage didn’t need this text-align workaround and didn’t know why. The reason turned out to be the DOCTYPE that was used. Using this DOCTYPE, you don’t need that text-align hack.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”&gt;

Reference:

Quicks mode and strict mode

Advertisements

From → Web Development

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: