Log in

View Full Version : Centering "tables" and columns with css


RedCherry
2008-12-10, 11:23 AM
Anyone know how to center a "table" of two columns using CSS? When I redesigned theredcherry, all the category pages (http://www.theredcherry.com/free-amateur-sex-links.php) are tableless and optimized for 1024 resolution. But in the bigger resolutions, it is all crammed to the left.

I used this:

/* --- LEFT SIDE BAR --- */
#menu {float: left; padding-left: 10px; padding-right: 10px; text-align: left; width: 200px}

/* --- MAIN PAGE CONTENT --- */
#content {width: 770px; float: left; text-align: left; margin-left: 5px; margin-bottom: 0px; padding-bottom: 0px; padding-left: 5px;}


I tried putting a big <div align="center"></div> around the whole thing, but that didn't work. When I tried different floats, they overlapped, lol. And % widths also didn't seem to work.

This is the first big project I did almost completely tableless, so I'm still learning. |huh

bDok
2008-12-10, 12:09 PM
What I'd do is create a container for the two other divs. on that container that holds the two divs you do a margin auto for the left and right sides.

So if your container is XYZ pxs wide... then it will auto adjust the margins on the side so it will be centered.

RedCherry
2008-12-10, 12:39 PM
Heh that worked, thanks. Now I just have to add the code to all the pages. |bananna|

MeatPounder
2008-12-10, 02:14 PM
Hi RedCherry, saw the pm reply but see bDok beat me to it :)