Jump to content

Centering <div> like a Table


Halcyon

Recommended Posts

Pardon my ignorance as I'm a CSS apprentice...Everybody talks about the advantages of CSS over Tables and I agree...but there is one condition (while using tables) I can't replicate while using CSS.I can center a Table in a window. If the window is resized the table will slide left/right accordingly and the table will remain centered in the window.With CSS I can only get the <div> to resize horizontally as the window changes sizes, but it remains align to the left either with a fix margin or a flexible margin...BUT this is not the same as it being centered in the window (i.e.- the left and right margin are the same size, until a minimum window size is reached.Is it possible to replicate this same Tables behavior while using CSS?Thanks.JCN

Link to comment
Share on other sites

This is pretty simple:

(X)HTML:<div id="name_on_box">text</div>CSS:#name_on_box { width: 400px; margin: 0 auto; }

And just so it's said: to make it work in IE, you must have a doctype. At least in XHTML

Link to comment
Share on other sites

This is pretty simple:
(X)HTML:<div id="name_on_box">text</div>CSS:#name_on_box { width: 400px; margin: 0 auto; }

And just so it's said: to make it work in IE, you must have a doctype. At least in XHTML

Thanks...this was so obvious, but the on-line CSS course I'm following was not clear about it (maybe because it was so obvious).Now I'm totally converted to CSS :-)JCN
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...