Centering a DIV

There are, unfortunately, many differences in the way Internet Explorer and Firefox and other browsers render HTML code. I encountered another difference between the way they parse HTML code today in code to center a div section.

If I use the following code, the layer demarcated by the <div> and </div> tags is centered when viewed in Firefox or Netscape, but not in Internet Explorer.

This should be a block of text centered within the page. The div tag used is as follows:

<div style="padding: 5px; width: 300; margin: auto; border: 3px black solid">

When viewed with Firefox or Netscape, the layer is centered within the page, but not in Internet explorer.

Note: Tested in Firefox 3.0, Internet Explorer 7.0, and Netscape 7.2 on a Windows XP system.

Next Pageright arrow