#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    6
    Rep Power
    0

    Centering a table with CSS


    I'm trying to center a table with CSS, because apparently putting align="center" in the table tag doesn't validate as HTML Strict.

    I've tried

    table.center
    {
    position: fixed;
    left: 50%;
    }


    but that makes the table go off of the page. I've tried all the options given on w3schools.com with their positioning lessons, but none of them work.

    Any suggestions?
  2. #2
  3. Retired
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Finland
    Posts
    9,143
    Rep Power
    2493
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Language" content="EN" />
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="Cache-Control" content="no-cache" />
        <meta name="Author" content="Jamie Burns" />
        <meta name="Description" content="" />
        <meta name="Keywords" content="" />	
    <title></title>
    <style type="text/css" title="centering">
    html, body {
    	margin-left: auto;
    	margin-right: auto;
    	}
    #centeredtable {
    	margin-left: auto;
    	margin-right: auto;
    }
    </style>	
    </head>
    <body>
    	<table id="centeredtable" style="border: 1px groove #000">
    		<tr>
    			<td>This is a test</td>
    		</tr>	
    	</table>		  													
    </body>
    </html>
    HTH

    Cheers,
    Jamie

    >_ skiFFie ? | Twitter

    __________________

    Let the might of your compassion arise to bring a quick end
    to the flowing stream of the blood and tears .....
    Please hear my anguished words of truth.

    __________________
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    6
    Rep Power
    0
    Thanks a lot, it worked.

IMN logo majestic logo threadwatch logo seochat tools logo