homepage Welcome to WebmasterWorld Guest from 23.23.8.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
Centering a table on the page
Centering a table on the page
Adam5000

5+ Year Member



 
Msg#: 3460400 posted 3:59 pm on Sep 25, 2007 (gmt 0)

I've got a page with a two row, two column table on it, and I've specified the width of the table as 300px as described below.

<table style="width: 300px">
<tr>
<td>
<p>Text 1 here.</p>
</td>
<td>
<p>Text 2 here.</p>
</td>
</tr>
<tr>
<td>
<p>Text 3 here.</p>
</td>
<td>
<p>Text 4 here.</p>
</td>
</tr>
</table>

Right now, the table is aligned with the left margin of the page, and I'd like it to be centered between the left and right margins.

Help!

 

whoisgregg

WebmasterWorld Senior Member whoisgregg us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3460400 posted 4:08 pm on Sep 25, 2007 (gmt 0)

You can set
text-align: center on the parent element and use margin: 0 auto; on the table itself.
Robin_reala

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3460400 posted 4:47 pm on Sep 25, 2007 (gmt 0)

You don't actually need the text-align: center on the parent, just the magin: 0 auto on the table will do.

Adam5000

5+ Year Member



 
Msg#: 3460400 posted 6:23 pm on Sep 25, 2007 (gmt 0)

Superb Robin and Gregg

That worked just fine. I had several tables to do, but they were all the same. They're all centered now and they look great. And because I'm using an external style sheet, I was able to do five pages all at the same time.

Fabulous Robin and Gregg

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved