Jump to content

Best way to align tables


zeidhaddadin

Recommended Posts

Hi all,I want to know which is the best way to align tables in an Strict XHTML site:1- If I used <center> </center> it doesn't validate it as strict.2- Aslo using align="center" ..3- I'm using the following css code to make it in the center:.table { margin-left : 300px; }But its not good..This is my html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>zeid1</title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link type="text/css" rel="stylesheet" href="STYLE.css" /></head><body><p><br /><br /><br /></p><p class="p1">Merry Chirstmas and happy new year 2007</p><form method="get" action="SEARCH.aspx"><center><table cellpadding="0" cellspacing="0" border="0"><tr><td class="td1"> </td></tr><tr><td class="td1"><input type="text" name="search" size="32" /> <input type="submit" value="Search Db" /></td></tr><tr><td class="td1"> </td></tr></table></center></form><p class="p1">Programmed using <span class="span1">ASP.NET</span></p></body></html>

Link to comment
Share on other sites

First of all, the CSS:

.table { margin-left : 300px; }

defines a class which you didn't include in your <table> tag. The period before "table" tells the browser that this is a defined class. By removing the period, you tell the browser to apply these styles to any table on your page. Remove the <center> and </center> tags from your code and change the CSS. You also need to remove the border attribute from your <table> tag and put in in the CSS. I've shown the changes to the CSS and markup below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>zeid1</title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link type="text/css" rel="stylesheet" href="STYLE.css" /><style type="text/css">table{  margin: auto;  border: none;}</style></head><body><p><br /><br /><br /></p><p class="p1">Merry Chirstmas and happy new year 2007</p><form method="get" action="SEARCH.aspx"><table cellpadding="0" cellspacing="0" border="0"><tr><td class="td1"> </td></tr><tr><td class="td1"><input type="text" name="search" size="32" /> <input type="submit" value="Search Db" /></td></tr><tr><td class="td1"> </td></tr></table></form><p class="p1">Programmed using <span class="span1">ASP.NET</span></p></body>

I haven't checked to see if it validates or not, but this should get you on the right track :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...