Lee
Lee

Reputation: 47

Centered table and margins are not working?

I have noticed that this forum I have written is fine in most browsers although in IE8 its to the left and not centered.

Its CSS is margin: auto auto, which works in most browsers.

I don't want to resort to going old fashioned and putting align="center" in the actual table properties.

Can anyone explain it ?

http://forum.bestlincs.co.uk/

Upvotes: 0

Views: 101

Answers (3)

Joshua Dwire
Joshua Dwire

Reputation: 5443

Try giving the table the following styles:

table{
   position:relative;
   left:-50%;
   margin-left:450px;
}

Does that center it?

Upvotes: 0

Billy Moat
Billy Moat

Reputation: 21050

To fix the centering issue you need to specify a doctype like so:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

To fix your spacing problem you need to look at the box model. Without the doctype your site was using the old box model which is:

width = width + border + padding

and

height = height + border + padding

You need to revsisit that now like so:

width = width - (border + padding)
height = height - (border + padding)

Hope that makes sense. You should use the above to adjust the width / height of any elemts on your page such as DIVs TDs etc.

Upvotes: 2

Quentin
Quentin

Reputation: 943134

You have (or rather, when I started writing this answer, you had) no Doctype, so IE assumes the site is using layout techniques from the IE 5 era and partially emulates that browser.

Add a Doctype to trigger Standards mode.

The HTML 5 Doctype looks like the best match for your site:

<!DOCTYPE HTML>

Upvotes: 3

Related Questions