Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

centering page with layers?

Posted 06 Aug 2005 08:44:41
1
has voted
06 Aug 2005 08:44:41 gil gallo posted:
can someone please share with me how i might center my home page with layering for different resolutions?
thanks a bunch

Replies

Replied 06 Aug 2005 09:16:49
06 Aug 2005 09:16:49 gil gallo replied:
center and div align center does not work outside of content using other div tags
Replied 08 Aug 2005 18:05:28
08 Aug 2005 18:05:28 myke black replied:
it is possible, although you have to do a bit of extra graft to get it working. Basically you need to get the width and height of the current browser window, then get the width and height of your div layer, then you reposition the top and left css attribute of the layer so that it centers ok. When I do this, I also set it so that the layer is initially hidden, and made visible after the page load because the page jumps to the centre when the page is loaded up. Heres some code for you:

<pre id=code><font face=courier size=2 id=code>

&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
body {left:0px;top:0px;}
#mainDiv {left:0px;top:0px;width:760;height:624;background-color<img src=../images/dmxzone/forum/icon_smile_tongue.gif border=0 align=middle>ink;position:absolute;visibility:hidden}
&lt;/style&gt;
&lt;/head&gt;
&lt;body onResize = setMiddle()&gt;
&lt;div id="mainDiv"&gt;
Here is the main div layer, put your content in here.

&lt;/div&gt;
&lt;script&gt;

function setMiddle(){
var sWidth = actualPageWidth();
var sHeight = actualPageHeight();
var mWidth = parseInt(document.getElementById("mainDiv".style.width)
var mHeight = parseInt(document.getElementById("mainDiv".style.height)
lMargin = (sWidth - mWidth)/2;
if (lMargin &lt; 0) lMargin="0";

tMargin = (sHeight - mHeight)/2;
if (tMargin &lt; 0) tMargin="0";
document.getElementById("mainDiv".style.left = lMargin + "px";
document.getElementById("mainDiv".style.top = tMargin + "px";
document.getElementById("mainDiv".style.visibility = "visible"
return false;
}

function actualPageHeight() {
if (window.innerHeight != null)
return window.innerHeight;
if (document.body.clientHeight != null)
return document.body.clientHeight;
return(null);
}

function actualPageWidth() {
if (window.innerWidth != null)
return window.innerWidth;
if (document.body.clientWidth != null)
return document.body.clientWidth;
return(null);
}

setMiddle()

window.onResize = setMiddle()
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;


</font id=code></pre id=code>

Alternatively, you can use tables, which is a lot easier.
Replied 08 Aug 2005 21:15:04
08 Aug 2005 21:15:04 Shane Gardner replied:
Replied 09 Aug 2005 00:34:31
09 Aug 2005 00:34:31 gil gallo replied:
wow, you guys are good. i work crazy hours, and I'm still not as proficient as you guys. How do I learn to be a master like you guys?
Replied 10 Aug 2005 19:09:33
10 Aug 2005 19:09:33 myke black replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> wow, you guys are good. i work crazy hours, and I'm still not as proficient as you guys. How do I learn to be a master like you guys?<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

blood, sweat, tears and plenty of caffeinated drinks.

Reply to this topic