Connecting Tech Pros Worldwide Forums | Help | Site Map

Centering CSS

Newbie
 
Join Date: Aug 2007
Posts: 15
#1: Jun 27 '08
I want to center the entire site, incase people have wide screen monitors. I'm suspecting it has something to do with the position being absolute but I dunno. I've been trying everything, so there might be some uneeded script. Heres the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <style type="text/css">
  3.  
  4. body {
  5.  
  6.  
  7. margin-top:0px;
  8. margin-bottom:0px;
  9. margin-left:0px;
  10. height:auto;
  11. text-align:center;
  12.  
  13.  
  14. }
  15.  
  16. P.wood { 
  17.    text-align: center;
  18.   }
  19.  
  20. div.all{
  21.    margin-left: auto;
  22.    margin-right: auto;
  23. }
  24. </style>
  25.  
  26.  
  27. </head>
  28. <body  bgcolor="black">
  29.  
  30. <DIV style="text-align:center;position: absolute; top:0px; left:0px; width:113px; height:0px">
  31. <DIV style="position: absolute; top:0px; left:437px; width:100px; height:15px;">
  32.     <table>
  33.       <tr>
  34.            <td><img src="abbadontitle.jpg" alt="About Us Pic" name="aboutus">
  35.  
  36.         </td>
  37.       </tr>
  38.     </table>
  39.   </DIV>
  40.  
  41. <DIV style="position: absolute; top:30px; left:42px; width:100px; height:15px;">
  42.     <table>
  43.       <tr>
  44.           <td><img src="mikefade4.jpg" alt="Our Services pic" name="ourservices">
  45.  
  46.         </td>
  47.       </tr>
  48.     </table>
  49.   </DIV>
  50.  
  51. <DIV style="position: absolute; top:20px; left:375px; width:100px; height:15px;">
  52.     <table>
  53.       <tr>
  54.         <td><img src="movietitle3.jpg" alt="Contact Us Pic" name="contactus">
  55.  
  56.         </td>
  57.       </tr>
  58.     </table>
  59.   </DIV>
  60.  
  61. <DIV style="position: absolute; top:0px; left:0px; width:00px; height:15px;">
  62.     <table>
  63.       <tr>
  64.         <td><img src="rightfilm.jpg" alt="Contact Us Pic" name="contactus">
  65.  
  66.         </td>
  67.       </tr>
  68.     </table>
  69.   </DIV>
  70.  
  71. <DIV style="position: absolute; top:0px; left:967px; width:00px; height:15px;">
  72.     <table>
  73.       <tr>
  74.         <td><img src="rightfilm.jpg" alt="Contact Us Pic" name="contactus">
  75.  
  76.         </td>
  77.       </tr>
  78.     </table>
  79.   </DIV>
  80.  
  81. <DIV style="position: absolute; top:700px; left:0px; width:00px; height:15px;">
  82.     <table>
  83.       <tr>
  84.         <td><img src="bottom.jpg" alt="Contact Us Pic" name="contactus">
  85.  
  86.         </td>
  87.       </tr>
  88.     </table>
  89.   </DIV>
  90.  
  91. <div style="position: absolute; top:300px; left:300px; width:0px; height:0px;">
  92.     <table>
  93.       <tr>
  94.         <td><object><param name="allowfullscreen" value="true" >
  95. <param name="allowscriptaccess" value="always" >
  96. <param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=890103&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1">
  97. <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=890103&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1"
  98.  type="application/x-shockwave-flash" 
  99. allowfullscreen="true" allowscriptaccess="always" width="400" height="240">
  100. </embed>
  101. </object>
  102.         </td>
  103.       </tr>
  104.     </table>
  105.   </DIV>
  106. </DIV>
  107.  
  108.  
  109.  
  110.  
  111. </body>
  112.  

Expert
 
Join Date: Oct 2006
Location: NC
Posts: 1,722
#2: Jun 27 '08

re: Centering CSS


Here's a link:

center
Newbie
 
Join Date: Aug 2007
Posts: 15
#3: Jun 28 '08

re: Centering CSS


I added the text-align:center; to the body selector and the margin: 0 auto to the container and it still won't work... i'll add the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <head>
  3.  
  4. <style type="text/css">
  5.  
  6. body {
  7.        text-align:center;
  8.        background-color: black;
  9.         }
  10.  
  11. #container {
  12.     margin: 0 auto;   /* align for good browsers */
  13.     text-align: left; /* counter the body center */
  14.  
  15. </style>
  16.  
  17.  
  18. </head>
  19. <body>
  20.  
  21. <DIV id="container">
  22. <DIV style="position: absolute; top:0px; left:437px; width:100px; height:15px;">
  23.     <table>
  24.       <tr>
  25.            <td><img src="abbadontitle.jpg" alt="About Us Pic" name="aboutus">
  26.  
  27.         </td>
  28.       </tr>
  29.     </table>
  30.   </DIV>
  31.  
  32. <DIV style="position: absolute; top:30px; left:42px; width:100px; height:15px;">
  33.     <table>
  34.       <tr>
  35.           <td><img src="mikefade4.jpg" alt="Our Services pic" name="ourservices">
  36.  
  37.         </td>
  38.       </tr>
  39.     </table>
  40.   </DIV>
  41.  
  42. <DIV style="position: absolute; top:20px; left:375px; width:100px; height:15px;">
  43.     <table>
  44.       <tr>
  45.         <td><img src="movietitle3.jpg" alt="Contact Us Pic" name="contactus">
  46.  
  47.         </td>
  48.       </tr>
  49.     </table>
  50.   </DIV>
  51.  
  52. <DIV style="position: absolute; top:0px; left:0px; width:00px; height:15px;">
  53.     <table>
  54.       <tr>
  55.         <td><img src="rightfilm.jpg" alt="Contact Us Pic" name="contactus">
  56.  
  57.         </td>
  58.       </tr>
  59.     </table>
  60.   </DIV>
  61.  
  62. <DIV style="position: absolute; top:0px; left:967px; width:00px; height:15px;">
  63.     <table>
  64.       <tr>
  65.         <td><img src="rightfilm.jpg" alt="Contact Us Pic" name="contactus">
  66.  
  67.         </td>
  68.       </tr>
  69.     </table>
  70.   </DIV>
  71.  
  72. <DIV style="position: absolute; top:700px; left:0px; width:00px; height:15px;">
  73.     <table>
  74.       <tr>
  75.         <td><img src="bottom.jpg" alt="Contact Us Pic" name="contactus">
  76.  
  77.         </td>
  78.       </tr>
  79.     </table>
  80.   </DIV>
  81.  
  82. <div style="position: absolute; top:300px; left:300px; width:0px; height:0px;">
  83.     <table>
  84.       <tr>
  85.         <td><object><param name="allowfullscreen" value="true" >
  86. <param name="allowscriptaccess" value="always" >
  87. <param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=890103&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1">
  88. <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=890103&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1"
  89.  type="application/x-shockwave-flash" 
  90. allowfullscreen="true" allowscriptaccess="always" width="400" height="240">
  91. </embed>
  92. </object>
  93.         </td>
  94.       </tr>
  95.     </table>
  96.   </DIV>
  97. </DIV>
  98.  
  99.  
  100.  
  101.  
  102. </body>
  103.  
  104.  
Newbie
 
Join Date: Jun 2008
Posts: 12
#4: Jun 29 '08

re: Centering CSS


actually it does seem to display correctly for me on IE7 and FF ...
the embeded video is centered at least . . .


one suggestion: if you want your other divs to display in the right or left corner, you should probably FLOAT them there instead of using absolute coordinates. right now they slightly exceed the width of my monitor set at 1024 x 768...

FLOAT will position the tags properly on wide & hi-res screens as well as for the poor sops using 800x600.
Reply