HighDots Forums  

centering page on screen

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss centering page on screen in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default centering page on screen - 11-06-2009 , 01:53 PM






Here is how I try to do it - but it does not work.
Could someone please tell me what I am doing wrong.
Every thing works ok until the line

document.getElementById("main").style.left = theOffset;

Thank you.

function centerLayout()
{
var layoutWidth = 900; // set the width of the page here
var bodyWidth = screen.availWidth;
var theOffset = ((bodyWidth - layoutWidth)/2) - 10;
if (theOffset > 0) {
document.getElementById("main").style.left = theOffset;
}

}



<BODY onLoad = "centerLayout()">
<div id="main" >
.....

Reply With Quote
  #2  
Old   
Andy
 
Posts: n/a

Default Re: centering page on screen - 11-07-2009 , 04:36 AM






<reg (AT) nospam (DOT) com> wrote

Quote:
Here is how I try to do it - but it does not work.
Could someone please tell me what I am doing wrong.
Every thing works ok until the line

document.getElementById("main").style.left = theOffset;

Thank you.

function centerLayout()
{
var layoutWidth = 900; // set the width of the page here
var bodyWidth = screen.availWidth;
var theOffset = ((bodyWidth - layoutWidth)/2) - 10;
if (theOffset > 0) {
document.getElementById("main").style.left = theOffset;
}

}



BODY onLoad = "centerLayout()"
div id="main"
.....
Hi,

This solution might be frowned upon, but it's simple and it works...


<table cellspacing="0" cellpadding="0" width="100%" height="*">
<td width="*">&nbsp;</td>
<td width="900" valign="top">CONTENT GOES HERE</td>
<td width="*">&nbsp;</td>
</table>


....hope this helps.

Andy

Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: centering page on screen - 11-08-2009 , 10:27 PM



On Sat, 7 Nov 2009 09:36:31 -0000, "Andy"
<andy (AT) REMOVETOEMAILmanyplay (DOT) com> wrote:

Quote:
reg (AT) nospam (DOT) com> wrote in message
news:itr8f5p2v9r8qfc8i75m2h9qi730im7hco (AT) 4ax (DOT) com...
Here is how I try to do it - but it does not work.
Could someone please tell me what I am doing wrong.
Every thing works ok until the line

document.getElementById("main").style.left = theOffset;

Thank you.

function centerLayout()
{
var layoutWidth = 900; // set the width of the page here
var bodyWidth = screen.availWidth;
var theOffset = ((bodyWidth - layoutWidth)/2) - 10;
if (theOffset > 0) {
document.getElementById("main").style.left = theOffset;
}

}



BODY onLoad = "centerLayout()"
div id="main"
.....

Hi,

This solution might be frowned upon, but it's simple and it works...


table cellspacing="0" cellpadding="0" width="100%" height="*"
td width="*">&nbsp;</td
td width="900" valign="top">CONTENT GOES HERE</td
td width="*">&nbsp;</td
/table


...hope this helps.

Andy


Thanks Andy

This code in fact sorted out the problem for me:

function centerLayout()
{
var layoutWidth = 900; // set the width of the page here
var bodyWidth = screen.availWidth;
var theOffset = ((bodyWidth - layoutWidth)/2)-10;
if (theOffset > 0) {
var o=document.getElementById("main");
var r=o.style;
r.position='absolute';
r.left = theOffset + 'px';
r.display = "block";
}
}

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.