Wrox Programmer Forums
|
CSS Cascading Style Sheets All issues relating to Cascading Style Sheets (CSS).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the CSS Cascading Style Sheets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2006, 12:00 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default align="center" in CSS

Code:
  <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
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old February 20th, 2006, 02:32 PM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this:

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

 
Old February 20th, 2006, 02:35 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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
 
Old February 21st, 2006, 05:45 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
  <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
 
Old February 21st, 2006, 05:48 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
  <td align="center">
  <table cellpadding="0" cellspacing="0" class="center_table">
also seems to work ok as well??

www.crmpicco.co.uk
 
Old February 21st, 2006, 09:31 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With CSS "Align" Property TheSchwa Other Programming Languages 1 October 22nd, 2007 03:38 PM
right align one part of cell and center the rest crmpicco HTML Code Clinic 0 February 21st, 2006 09:09 AM
CSS Text Align webnitro CSS Cascading Style Sheets 3 December 8th, 2005 01:19 PM
TextBox (Align Center) Problem on Printing mrhyman VB How-To 9 February 19th, 2004 12:14 PM
align Center melvik C# 1 September 7th, 2003 04:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.