Why wont this center? *link* *Easy*

Discussion in 'HTML & Website Design' started by yfzcentral, Mar 2, 2007.

  1. #1
    Been working on this for awhile.

    http://www.yfzcentral.com/test123.php

    The fading images javascript doesn't want to center for some reason. Tried everything, but no luck.

    Any ideas?

    Thanks!

    PS: Here is the coding

    
    <style type="text/css">
        #image1 {
          height: 160px;
    	  postition: relative;
        }
        
        #image1 img {
          display: none;
          border: none;
        }
        </style>
        <script language="JavaScript">
        
        window.addEventListener?window.addEventListener("load",init,false):window.attachEvent("onload",init);
        
        function init() {
          div = document.getElementById("image1");
          imgs = div.getElementsByTagName("img");
          
          imgs[0].style.display="block";
          imgs[0].style.position = "absolute";
          imgs[0].xopacity = .99;
          imageList = imgs;
          startingIndex = 0;
          setTimeout(startFade, 6000);
        }
        
        var imageList;
        var startingIndex;
        
        function startFade() {
        
          nextIndex = imageList[startingIndex+1]?startingIndex+1:0;
          
          imageList[startingIndex].xopacity -= .05;
          imageList[nextIndex].xopacity = imageList[nextIndex].xopacity? imageList[nextIndex].xopacity+.05:0.05;
          
          setOpacity(imageList[startingIndex]);
          setOpacity(imageList[nextIndex]);
          imageList[nextIndex].style.display="block";
          
          if (imageList[startingIndex].xopacity <= 0) {
            imageList[startingIndex].xopacity = 0;
            imageList[startingIndex].style.display = "none";
            imageList[nextIndex].style.position = "absolute";
            startingIndex = nextIndex;
            setTimeout(startFade, 6000);
          } else {
            setTimeout(startFade, 40);
          }
          
        }
        
        function setOpacity(obj) {
          if (obj.xopacity > .99) {
            obj.xopacity = .99;
            return;
          }
          obj.style.opacity = obj.xopacity;
          obj.style.mozOpacity = obj.xopacity;
          obj.style.filter = "alpha(opacity=" + (obj.xopacity*100) + ")";
        }
        
    </script>
    
    PHP:
    
      <tr> 
          <td>
            <div id="image1" align="center"><a href="http://www.yfzcentral.com/qotm"><img style="display: block; position: absolute; opacity: 0.95;" src="../new2/front/qotm.jpg" border="0" height="160" width="830"></a><a href="http://www.yfzcentral.com/potm"><img style="opacity: -0.01; display: none; position: absolute;" src="../new2/front/potm.jpg" border="0" height="160" width="830"></a>
    		</div>        
          </td>
        </tr>
    
    PHP:
     
    yfzcentral, Mar 2, 2007 IP
  2. Xangis

    Xangis Active Member

    Messages:
    182
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    78
    #2
    Please take this with a grain of salt, since I am not a CSS expert, but it looks like the image is flagged as being the "image1" style. That causes the align="center" to be ignored and instead use the tags in the image1 style, which are height: 160px and position: relative, but mentions nothing of being centered.

    Try adding:
    text-align:center;
    to the image1 style and see what happens. You might need a different tag to center an image, but that should be a good start.
     
    Xangis, Mar 2, 2007 IP