Can't center webpage?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elizarod
    New Member
    • Nov 2011
    • 3

    Can't center webpage?

    I'm building my first website without any prior knowledge of html or css programming, so noob question here: I cannot align my website's homepage to the center. I've tried trouble shooting this for a few hours, and none of the solutions work.

    I have all of my images in a DIV called wrap. Whatever I try, it doesn't seem to affect it's positioning.

    Also, please ignore any alignment issues with the images, I've jumbled everything's position up while trying to get this right.

    Thanks for the help!





    Code:
     
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Lizzy's Web Page</title>
    <style type="text/css">
    
    
    body {
    	background-color: #ece5e5;
    }
    
    
    
    
    #wrap {
    	width:1200px;
    	height:816px;
    	margin-top: 0px;
    	margin-right: auto;
    	margin-bottom: 0px;
    	margin-left: auto;
    	
    	
    }
    
    #HarryDiv {
    	position:absolute;
    	left:939px;
    	width:496px;
    	height:674px;
    	z-index:2;
    	bottom: 4px;
    	margin-top: 55px;
    }
    #name {
    	position:absolute;
    	left:593px;
    	top:30px;
    	width:300px;
    	height:358px;
    	z-index:2;
    }
    #apDiv2 {
    	position:absolute;
    	left:209px;
    	top:8px;
    	width:436px;
    	height:410px;
    	z-index:2;
    }
    #contact {
    	position:absolute;
    	left:625px;
    	top:528px;
    	width:73px;
    	height:41px;
    	z-index:1;
    }
    #about {
    	position:absolute;
    	left:636px;
    	top:474px;
    	width:51px;
    	height:37px;
    	z-index:1;
    }
    #work {
    	position:absolute;
    	left:637px;
    	top:418px;
    	width:47px;
    	height:39px;
    	z-index:1;
    }
    #blog {
    	position:absolute;
    	left:643px;
    	top:586px;
    	width:39px;
    	height:44px;
    	z-index:1;
    }
    #cat {
    	position:absolute;
    	left:245px;
    	top:384px;
    	width:343px;
    	height:290px;
    	z-index:1;
    }
    </style>
    
    
    <script type="text/javascript">
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    
    </script>
    
    
    </head>
    
    
    
    <body onload="MM_preloadImages('Images/butterhead_angry.png')">
    
    
    <div id="wrap">
    
    
        <div id="HarryDiv"><img src="Images/harry.png" alt="harry" width="501" height="678" class="harry" /></div>
        
        <div id="name"><img src="Images/lizrodriguez.png" width="305" height="360" alt="name" /></div>
        
        <div id="apDiv2"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Professor Head','','Images/butterhead_angry.png',1)"><img src="Images/butterhead.png" name="Professor Head" width="441" height="408" border="0" id="Professor Head" /></a></div>
        
        <div id="work"><img src="Images/work.png" width="47" height="37" alt="work" /></div>
        
        <div id="about"><img src="Images/about.png" width="51" height="37" alt="about" /></div>
        
        <div id="contact"><img src="Images/contact.png" width="72" height="40" alt="contact" /></div>
        
        <div id="blog"><img src="Images/blog.png" width="39" height="45" alt="blog" /> </div>
        
        <div id="cat"><img src="Images/henryhead.png" width="332" height="283" alt="henry" /> </div>
    </div>
    
    
    
    </body>
    </html>
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    Your page is already centred (i.e. div with id wrap) but you are using absolute positioning which cause to appear as you see it.

    Comment

    • veerjeet
      New Member
      • Feb 2013
      • 2

      #3
      in body
      Code:
       body {
          min-width:960px;
          background-color: #ece5e5;
      }

      Once try this
      Last edited by Rabbit; Feb 25 '13, 07:04 PM. Reason: Please use code tags when posting code.

      Comment

      Working...