Forum Moderators: not2easy
In future, absolutely positioning an entire website has the pro of pixel-perfecting a layout, but places many restrictions on the things you can do with the layout.
Now, there is one way you can fix this, which won't terribly affect the rest of your code:
div, the element that surrounds every other element in your website (you can't center a website without it being a fixed width); divs-width, so if your width was 770px (just enough for 800*600 maximised resolution,) then you would set margin-left to be -385px;And that should be that :)
Why does this work:
Because we're not trying to get something that's out of the document flow to be in it, we're just working within the already-out-of-the-document-flow system.
We're setting a left property to 50%, but this is calculated by the top-left edge - thus we need something to make it calculate it from the center...
So we set the margin-left to negative half of the width, and that's how it works ;)
P.S.: If anyone knows of an external method of fixing this...such as external scripting that automatically reads the resolution of the viewer's screen and adjusts my website to fit that resolution...I would appreciate it if a link could be supplied.
[edited by: PerlJamZ10 at 7:04 pm (utc) on Dec. 20, 2006]
But can often be destroyed when the user changes his/her font sizes. It depends on how things are positioned. I generally avoid absolute positioning for this reason alone.
Definitely agreed, absolute positioning is like salt - don't use too much, but a little here and there is fine.
P.S.: If anyone knows of an external method of fixing this...such as external scripting that automatically reads the resolution of the viewer's screen and adjusts my website to fit that resolution...I would appreciate it if a link could be supplied.
PerlJamZ10, the point is that this shouldn't be necessary at all. There are thousands of centered CSS websites, which require very few lines of code.
Would you be able to post the CSS code that affects
html, body, and the container div (the one that contains all your other elements)? I get the feeling there's something interfering here, like your absolute positioning is ruining the methods for alignment.
What we may have to do is:
div immediately within the main containing div, that also contains everything, that is set to position relative (with no other properties.)And see whether that fixes it. But again, could we see the relevant 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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
width:1003px;
height:720px;
left: 180.5px;
top: 0px;
z-index: 1;
}
#Layer2 {
position:absolute;
width:148px;
height:77px;
z-index:1;
left: 306px;
top: 240px;
}
#Layer3 {
position:absolute;
width:355px;
height:90px;
z-index:2;
left: 536px;
top: 345px;
}
#Layer4 {
position:absolute;
width:144px;
height:57px;
z-index:3;
left: 750px;
top: 543px;
}
#Layer5 {
position:absolute;
width:944px;
height:144px;
z-index:4;
top: 1px;
left: 37px;
}
#Layer6 {
position:absolute;
width:274px;
height:534px;
z-index:5;
left: 9px;
top: 150px;
}
-->
</style>
<script type="text/JavaScript">
<!--
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_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_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>
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW ¦¦ innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<link href="The Website.css" rel="stylesheet" type="text/css" />
</head>
<body onload="MM_preloadImages('../Working Folder/images/INFO-ROLL.gif','../Working Folder/images/PORTFOLIO-ROLL.gif','../Working Folder/images/CONTACT-ROLL.gif')">
<div id="Layer1">
<div id="Layer6">
<div align="left"> <img src="../Working Folder/images/GRAPHIC-ARTIST_03.gif" width="274" height="534" /></div>
</div>
<div id="Layer5">
<div align="left"> <img src="../Working Folder/images/_03.gif" width="944" height="144" /></div>
</div>
<div id="Layer4">
<div align="left"> <a href="Contact.html"><img src="../Working Folder/images/CONTACT.gif" alt="contact" name="contact" width="144" height="57" border="0" id="contact" onmouseover="MM_swapImage('contact','','../Working Folder/images/CONTACT-ROLL.gif',1)" onmouseout="MM_swapImgRestore()" /></a></div>
</div>
<div id="Layer3">
<div align="left"> <a href="Portfolio-1-Eggs.html"><img src="../Working Folder/images/PORTFOLIO.gif" alt="portfolio" name="portfolio" width="355" height="90" border="0" id="portfolio" onmouseover="MM_swapImage('portfolio','','../Working Folder/images/PORTFOLIO-ROLL.gif',1)" onmouseout="MM_swapImgRestore()" /></a></div>
</div>
<div id="Layer2">
<div align="left"> <a href="Artist Info.html"><img src="../Working Folder/images/INFO.gif" alt="info" name="info" width="148" height="77" border="0" id="info" onmouseover="MM_swapImage('info','','../Working Folder/images/INFO-ROLL.gif',1)" onmouseout="MM_swapImgRestore()" /></a></div>
</div>
<div align="left"> <img src="MAIN-PAGE.gif" width="1003" height="720" /></div>
</div>
</body>
</html>
And here is the CSS that im working with. What is posted centers the image all-around on my normal resolution setting. When I change the resolution it still remains centered, but it's stuck against the left wall of the browser:
#Layer1 {
width: 720px;
height: 1003px;
margin-left: -180px;
margin-top: 250.75px;
margin-right: -180px;
margin-bottom: 501.5px;
}
[edited by: PerlJamZ10 at 11:12 pm (utc) on Dec. 20, 2006]
Okay, you have left and top properties set for pretty much all your inner elements, so this is what you have to do:
div inside Layer1 that encompasses all your other divs also; #Layer1 { width: 720px;
left: 50%;
margin-left: -360px; }Just to make it clear, the
div inside #Layer1 will have to be: #Layer1 div#inside-Layer1 { position: relative; } And all your other
divs will be inside div#inside-Layer1. And again, for future reference, absolutely positioning an entire website is a bad idea :)