How do you center a div tag?

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,824
6,823
136
I want to center a box I made using the div tag. How do you center a div on the page? My current knowledge says "wrap it in a table and center the table", but there has to be a more elegant way of doing this. TIA.
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
<div align="center">...</div>

EDIT: Whoops, nm, that centers text within a div. :eek:
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
make a div tag that spans the entire page that has align=center, place your div tag within it...
 

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,824
6,823
136
Originally posted by: Drakkon
make a div tag that spans the entire page that has align=center, place your div tag within it...

Nice, thanks! A couple more questions:

I suppose there's still no good way of creating an auto-center for the vertical as well? If there isn't, is the best way to drop the div box down to the middle of the page by using CSS positioning?

Also, how do you make a drop-down menu a specific length? It looks dumb when it's shorter than my input fields which have a maxlength of 20.

Here's the code, if you're interested in a nice, simple login box for multiple systems:
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
the centering vert is kinda been a debated issue for a long time. You can do it via javascript but for each browser it ends up being wierd.I'd say the best way is to use CSS to position where "center" on a 1024x768 screen and use that as a guide

To make the box the same "width" Id say throw a style="width:150px" into each 'input' and 'select' tag it will make all your boxes 150px wide and thus creating the illusion of them being all the same size.