Subject: align="center" in CSS
Posted By: crmpicco Post Date: 2/20/2006 11:00:41 AM

  <table border="1" bordercolor="#000000" align="center" cellpadding="0" cellspacing="0" width="360px">

I am building a table with the code above, is there a way to align the table center with CSS?

Picco

www.crmpicco.co.uk
Reply By: ceadge Reply Date: 2/20/2006 1:32:16 PM
Try this:

table
{
margin-left: auto;
margin-right: auto;
}

Reply By: richard.york Reply Date: 2/20/2006 1:35:05 PM
Or simply

margin: auto;

or more precisely

margin: 0 auto;  

In the second one, top and bottom margins are zero as auto has no effect on the top and bottom, left and right are auto.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply By: crmpicco Reply Date: 2/21/2006 4:45:31 AM

  <td style="margin:0 auto">
  <table cellpadding="0" cellspacing="0" class="center_table">

using margin: 0 auto on the <td> cell doesnt seem to work, but when i put the align="center" back into the table its fine? the table 'center_table' is in a td cell. is there a way to put a style on the <td> that will align center?

www.crmpicco.co.uk
Reply By: crmpicco Reply Date: 2/21/2006 4:48:15 AM

  <td align="center">
  <table cellpadding="0" cellspacing="0" class="center_table">

also seems to work ok as well??

www.crmpicco.co.uk
Reply By: richard.york Reply Date: 2/21/2006 8:31:46 AM
margin: auto works on tables and block elements.  So it doesn't center the contents of a cell, it centers the table.  For the contents of the cell to be centered, it depends on what is in them.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design

Go to topic 38824

Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360
Return to index page 359
Return to index page 358
Return to index page 357
Return to index page 356
Return to index page 355
Return to index page 354