homepage Welcome to WebmasterWorld Guest from 54.237.95.6
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: DrDoc

CSS Forum

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




msg:3460402
 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




msg:3460420
 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




msg:3460454
 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




msg:3460578
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved