473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to center a table?

347 100+
I have a web page that I converted from a psd file to html with Photoshop and imported into Dreamweaver. The problem I'm having is that some viewers comment on the fact that the page is left justified. I inserted a div tag into the html with a wrap around selection and tried to modify the css rules so that this would align properly, and the page is still aligning left justified. Here is the code that I have for my css:

Expand|Select|Wrap|Line Numbers
  1. #site_layout {
  2.     font-family: "Franklin Gothic Demi Cond";
  3.     background-color: #FFF;
  4.     height: auto;
  5.     width: auto;
  6.     margin-left: auto;
  7.     margin-right: auto;
  8. }
  9.  
and here is the html for the web site:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>MSB secondary page template</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <link href="site_layout.css" rel="stylesheet" type="text/css">
  6. </head>
  7. <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  8. <!-- Save for Web Slices (MSB secondary page template.psd) -->
  9. <div id="container">
  10.   <div id="site_layout">
  11.     <div class="css" id="site_layout.css">
  12.       <table width="1260" height="811" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  13.         <tr>
  14.           <td colspan="26" align="center" bgcolor="#FFFFFF">
  15.             <img src="images/MSB-secondary-page-template_01.gif" width="1259" height="24" alt=""></td>
  16.           <td>
  17.             <img src="images/spacer.gif" width="1" height="24" alt=""></td>
  18.           </tr>
  19.         <tr>
  20.           <td colspan="20" rowspan="2" align="center" bgcolor="#FFFFFF">
  21.             <img src="images/MSB-secondary-page-template_02.gif" width="1036" height="48" alt=""></td>
  22.           <td colspan="2" align="center" bgcolor="#FFFFFF">
  23.             <img src="images/MSB-secondary-page-template_03.jpg" width="60" height="22" alt=""></td>
  24.           <td colspan="4" rowspan="5" align="center" bgcolor="#FFFFFF">
  25.             <img src="images/MSB-secondary-page-template_04.gif" width="163" height="65" alt=""></td>
  26.           <td>
  27.             <img src="images/spacer.gif" width="1" height="22" alt=""></td>
  28.           </tr>
  29.         <tr>
  30.           <td colspan="2" rowspan="4" align="center" bgcolor="#FFFFFF">
  31.             <img src="images/MSB-secondary-page-template_05.gif" width="60" height="43" alt=""></td>
  32.           <td>
  33.             <img src="images/spacer.gif" width="1" height="26" alt=""></td>
  34.           </tr>
  35.         <tr>
  36.           <td colspan="19" align="center" bgcolor="#FFFFFF">
  37.             <img src="images/MSB-secondary-page-template_06.gif" width="873" height="8" alt=""></td>
  38.           <td rowspan="5" align="center" bgcolor="#FFFFFF">
  39.             <img src="images/MSB-secondary-page-template_07.jpg" width="163" height="58" alt=""></td>
  40.           <td>
  41.             <img src="images/spacer.gif" width="1" height="8" alt=""></td>
  42.           </tr>
  43.         <tr>
  44.           <td colspan="3" rowspan="5" align="center" bgcolor="#FFFFFF">
  45.             <img src="images/MSB-secondary-page-template_08.gif" width="166" height="51" alt=""></td>
  46.           <td rowspan="5" align="center" bgcolor="#FFFFFF">
  47.             <img src="images/MSB-secondary-page-template_09.jpg" width="120" height="51" alt=""></td>
  48.           <td rowspan="5" align="center" bgcolor="#FFFFFF">
  49.             <img src="images/MSB-secondary-page-template_10.gif" width="16" height="51" alt=""></td>
  50.           <td rowspan="5" align="center" bgcolor="#FFFFFF">
  51.             <img src="images/MSB-secondary-page-template_11.jpg" width="120" height="51" alt=""></td>
  52.           <td colspan="13" align="center" bgcolor="#FFFFFF">
  53.             <img src="images/MSB-secondary-page-template_12.gif" width="451" height="1" alt=""></td>
  54.           <td>
  55.             <img src="images/spacer.gif" width="1" height="1" alt=""></td>
  56.           </tr>
  57.         <tr>
  58.           <td rowspan="4" align="center" bgcolor="#FFFFFF">
  59.             <img src="images/MSB-secondary-page-template_13.gif" width="19" height="50" alt=""></td>
  60.           <td colspan="2" rowspan="4" align="center" bgcolor="#FFFFFF">
  61.             <img src="images/MSB-secondary-page-template_14.jpg" width="119" height="50" alt=""></td>
  62.           <td colspan="2" rowspan="4" align="center" bgcolor="#FFFFFF">
  63.             <img src="images/MSB-secondary-page-template_15.gif" width="22" height="50" alt=""></td>
  64.           <td colspan="4" rowspan="4" align="center" bgcolor="#FFFFFF">
  65.             <img src="images/MSB-secondary-page-template_16.jpg" width="118" height="50" alt=""></td>
  66.           <td rowspan="4" align="center" bgcolor="#FFFFFF">
  67.             <img src="images/MSB-secondary-page-template_17.gif" width="19" height="50" alt=""></td>
  68.           <td colspan="2" rowspan="4" align="center" bgcolor="#FFFFFF">
  69.             <img src="images/MSB-secondary-page-template_18.jpg" width="118" height="50" alt=""></td>
  70.           <td rowspan="4" align="center" bgcolor="#FFFFFF">
  71.             <img src="images/MSB-secondary-page-template_19.gif" width="36" height="50" alt=""></td>
  72.           <td>
  73.             <img src="images/spacer.gif" width="1" height="8" alt=""></td>
  74.           </tr>
  75.         <tr>
  76.           <td rowspan="3" align="center" bgcolor="#FFFFFF">
  77.             <img src="images/MSB-secondary-page-template_20.gif" width="8" height="42" alt=""></td>
  78.           <td colspan="2" align="center" bgcolor="#FFFFFF">
  79.             <img src="images/MSB-secondary-page-template_21.jpg" width="58" height="24" alt=""></td>
  80.           <td colspan="3" rowspan="3" align="center" bgcolor="#FFFFFF">
  81.             <img src="images/MSB-secondary-page-template_22.gif" width="157" height="42" alt=""></td>
  82.           <td>
  83.             <img src="images/spacer.gif" width="1" height="24" alt=""></td>
  84.           </tr>
  85.         <tr>
  86.           <td colspan="2" rowspan="2" align="center" bgcolor="#FFFFFF">
  87.             <img src="images/MSB-secondary-page-template_23.gif" width="58" height="18" alt=""></td>
  88.           <td>
  89.             <img src="images/spacer.gif" width="1" height="17" alt=""></td>
  90.           </tr>
  91.         <tr>
  92.           <td align="center" bgcolor="#FFFFFF">
  93.             <img src="images/MSB-secondary-page-template_24.gif" width="163" height="1" alt=""></td>
  94.           <td>
  95.             <img src="images/spacer.gif" width="1" height="1" alt=""></td>
  96.           </tr>
  97.         <tr>
  98.           <td rowspan="4" align="center" bgcolor="#FFFFFF">
  99.             <img src="images/MSB-secondary-page-template_25.gif" width="148" height="665" alt=""></td>
  100.           <td colspan="15" align="center" bgcolor="#FFFFFF">
  101.             <img src="images/MSB-secondary-page-template_26.jpg" width="571" height="221" alt=""></td>
  102.           <td colspan="8" align="center" bgcolor="#FFFFFF">
  103.             <img src="images/MSB-secondary-page-template_27.jpg" width="405" height="221" alt=""></td>
  104.           <td colspan="2" rowspan="4" align="center" bgcolor="#FFFFFF">
  105.             <img src="images/MSB-secondary-page-template_28.gif" width="135" height="665" alt=""></td>
  106.           <td>
  107.             <img src="images/spacer.gif" width="1" height="221" alt=""></td>
  108.           </tr>
  109.         <tr>
  110.           <td rowspan="3" align="center" bgcolor="#FFFFFF">
  111.             <img src="images/MSB-secondary-page-template_29.gif" width="1" height="444" alt=""></td>
  112.           <td colspan="22" align="center" bgcolor="#FFFFFF">
  113.             <img src="images/MSB-secondary-page-template_30.gif" width="975" height="402" alt=""></td>
  114.           <td>
  115.             <img src="images/spacer.gif" width="1" height="402" alt=""></td>
  116.           </tr>
  117.         <tr>
  118.           <td colspan="6" rowspan="2" align="center" bgcolor="#FFFFFF">
  119.             <img src="images/MSB-secondary-page-template_31.gif" width="388" height="42" alt=""></td>
  120.           <td colspan="2" align="center" bgcolor="#FFFFFF">
  121.             <img src="images/MSB-secondary-page-template_32.jpg" width="44" height="21" alt=""></td>
  122.           <td colspan="2" rowspan="2" align="center" bgcolor="#FFFFFF">
  123.             <img src="images/MSB-secondary-page-template_33.gif" width="12" height="42" alt=""></td>
  124.           <td align="center" bgcolor="#FFFFFF">
  125.             <img src="images/MSB-secondary-page-template_34.jpg" width="77" height="21" alt=""></td>
  126.           <td rowspan="2" align="center" bgcolor="#FFFFFF">
  127.             <img src="images/MSB-secondary-page-template_35.gif" width="10" height="42" alt=""></td>
  128.           <td colspan="3" align="center" bgcolor="#FFFFFF">
  129.             <img src="images/MSB-secondary-page-template_36.jpg" width="53" height="21" alt=""></td>
  130.           <td colspan="7" rowspan="2" align="center" bgcolor="#FFFFFF">
  131.             <img src="images/MSB-secondary-page-template_37.gif" width="391" height="42" alt=""></td>
  132.           <td>
  133.             <img src="images/spacer.gif" width="1" height="21" alt=""></td>
  134.           </tr>
  135.         <tr>
  136.           <td colspan="2" align="center" bgcolor="#FFFFFF">
  137.             <img src="images/MSB-secondary-page-template_38.gif" width="44" height="21" alt=""></td>
  138.           <td align="center" bgcolor="#FFFFFF">
  139.             <img src="images/MSB-secondary-page-template_39.gif" width="77" height="21" alt=""></td>
  140.           <td colspan="3" align="center" bgcolor="#FFFFFF">
  141.             <img src="images/MSB-secondary-page-template_40.gif" width="53" height="21" alt=""></td>
  142.           <td>
  143.             <img src="images/spacer.gif" width="1" height="21" alt=""></td>
  144.           </tr>
  145.         <tr>
  146.           <td colspan="25" align="center" bgcolor="#FFFFFF">
  147.             <img src="images/MSB-secondary-page-template_41.jpg" width="1250" height="14" alt=""></td>
  148.           <td align="center" bgcolor="#FFFFFF">
  149.             <img src="images/MSB-secondary-page-template_42.gif" width="9" height="14" alt=""></td>
  150.           <td>
  151.             <img src="images/spacer.gif" width="1" height="14" alt=""></td>
  152.           </tr>
  153.         <tr>
  154.           <td>
  155.             <img src="images/spacer.gif" width="148" height="1" alt=""></td>
  156.           <td>
  157.             <img src="images/spacer.gif" width="1" height="1" alt=""></td>
  158.           <td>
  159.             <img src="images/spacer.gif" width="17" height="1" alt=""></td>
  160.           <td>
  161.             <img src="images/spacer.gif" width="120" height="1" alt=""></td>
  162.           <td>
  163.             <img src="images/spacer.gif" width="16" height="1" alt=""></td>
  164.           <td>
  165.             <img src="images/spacer.gif" width="120" height="1" alt=""></td>
  166.           <td>
  167.             <img src="images/spacer.gif" width="19" height="1" alt=""></td>
  168.           <td>
  169.             <img src="images/spacer.gif" width="96" height="1" alt=""></td>
  170.           <td>
  171.             <img src="images/spacer.gif" width="23" height="1" alt=""></td>
  172.           <td>
  173.             <img src="images/spacer.gif" width="21" height="1" alt=""></td>
  174.           <td>
  175.             <img src="images/spacer.gif" width="1" height="1" alt=""></td>
  176.           <td>
  177.             <img src="images/spacer.gif" width="11" height="1" alt=""></td>
  178.           <td>
  179.             <img src="images/spacer.gif" width="77" height="1" alt=""></td>
  180.           <td>
  181.             <img src="images/spacer.gif" width="10" height="1" alt=""></td>
  182.           <td>
  183.             <img src="images/spacer.gif" width="20" height="1" alt=""></td>
  184.           <td>
  185.             <img src="images/spacer.gif" width="19" height="1" alt=""></td>
  186.           <td>
  187.             <img src="images/spacer.gif" width="14" height="1" alt=""></td>
  188.           <td>
  189.             <img src="images/spacer.gif" width="104" height="1" alt=""></td>
  190.           <td>
  191.             <img src="images/spacer.gif" width="36" height="1" alt=""></td>
  192.           <td>
  193.             <img src="images/spacer.gif" width="163" height="1" alt=""></td>
  194.           <td>
  195.             <img src="images/spacer.gif" width="8" height="1" alt=""></td>
  196.           <td>
  197.             <img src="images/spacer.gif" width="52" height="1" alt=""></td>
  198.           <td>
  199.             <img src="images/spacer.gif" width="6" height="1" alt=""></td>
  200.           <td>
  201.             <img src="images/spacer.gif" width="22" height="1" alt=""></td>
  202.           <td>
  203.             <img src="images/spacer.gif" width="126" height="1" alt=""></td>
  204.           <td>
  205.             <img src="images/spacer.gif" width="9" height="1" alt=""></td>
  206.           <td></td>
  207.           </tr>
  208.       </table>
  209.     </div>
  210.   </div>
  211. </div>
  212. <!-- End Save for Web Slices -->
  213. </body>
  214. </html>
  215.  
Can someone please tell me what I'm doing wrong or not seeing?

Thank you

Doug
Dec 13 '10 #1
10 2576
This is bad HTML, you should consider making the HTML en CSS yourself and not let Photoshop do this. Photoshop is a great image editing software but not for development.

And tables are not meant to be used for layout construction, you make divisions with the <div>-tag.

First convert your layout to a semantic layout and then we'll be able to help you much better.

B.
Dec 14 '10 #2
JKing
1,206 Expert 1GB
What browser are you viewing this in? If IE provide the version as well.
Dec 14 '10 #3
dougancil
347 100+
Bryan,

Unfortunately since this is a psd file that I had to convert, there's really not a lot I can do about the html that's generated. I'm limited to that because I have to convert the psd file to html.

JKing, the version is IE 8 in Windows 7.
Dec 14 '10 #4
JKing
1,206 Expert 1GB
I can't replicate the issue unfortunately. The align="center" on the table should be enough to keep your page centered. Centers for me in both FF and IE8.

Is this a resolution issue for some users?
Dec 14 '10 #5
Uhh..
Expand|Select|Wrap|Line Numbers
  1. <div class="css" id="site_layout.css">
Thats just not right..

Use:
Expand|Select|Wrap|Line Numbers
  1. <div id="site_layout">
If this doesn't help, do you have a online example?

Bryan.
Dec 14 '10 #6
dougancil
347 100+
Bryan,

I have this

Expand|Select|Wrap|Line Numbers
  1. <div id="container">
  2.   <div id="site_layout">
  3.     <div class="css" id="site_layout.css">
  4.  
so you're saying to combine div id and div class together?
Dec 14 '10 #7
No, your usage of the id of the div is wrong.
-"site_layout.css" is the name of your css file
-your id in your css is #site_layout so your syntax should be: <div id="site_layout"> that how you set a id on a div.
-why calling your div class "css", no idea. Its a bad practice usage, use more describing names.

Bryan.

-edit-
Link: http://www.w3schools.com/css/css_id_class.asp

-edit2-
More direct link: http://www.w3schools.com/css/tryit.a...ycss_syntax_id
Dec 14 '10 #8
dougancil
347 100+
Jking,

the resolution on the computer in question is 1680x1050.
Dec 14 '10 #9
dougancil
347 100+
I fixed it with the code that you sent Bryan. Thank you.
Dec 14 '10 #10
Glad to help dougancil :)

Bryan.
Dec 14 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: George Ziniewicz | last post by:
.. I try to use CSS when possible, though I am still learning and don't maximize its use. In particular, I still use a table to provide for a centered image in a few slideshows (though table...
10
by: john T | last post by:
Is there anyway to vertically center a html table using css in such a way it does not alter the html table. When I tryied it just screws up.
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
1
by: Kenneth | last post by:
Okay, I've been scouring Google for hours looking for a solution to this problem, but as of yet I can't find one. XHTML Transitional seems to specify that I can no longer set a table's height to...
3
by: yawnmoth | last post by:
I'm trying to center list elements in a webpage I'm working on, and setting margin-left to auto for ol (or ul) seems to prevent the number (or bullet) from displaying in IE6 (strict mode) and...
2
by: autogoor | last post by:
I have a table and, in one cell of it, I have another table. How can I center the second table in the cell with css? Thanks, autogoor
3
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a...
5
by: Markus Ernst | last post by:
Hello This is a test example: http://www.markusernst.ch/anthracite/ http://www.markusernst.ch/anthracite/living_divani.html After googling and experimenting for several hours, I ended up...
9
by: Neal | last post by:
http://www.brassattackofspringfield.com/gigs.html CSS at http://www.brassattackofspringfield.com/default.css Opera and IE render caption as desired. Firefox does not. Why? And is there a fix?
1
by: =?Utf-8?B?ZnJhbmt5?= | last post by:
Hello, I've created a table that has two rows that are span across three columns. The third row has three columns, each with an image. The last row is also span accross three columns. The span...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.