Postioning a <div>

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Can someone please tell me how to make sure a always pops up in the center of the page?

Thanx in advanx

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Morning Jack,

Gee, you don't want much, huh? Smiling
OK, I've never needed to, but if you mean for resizings, etc. Try one of the following:
1) For IE: document.all.divID.align = "center"; NN4 has no such command, so you'll have to determine it on the fly (see # 3 for ideas)
2) place it within a cell in the middle of the page. If the div is more than text, you may have problems with NN 4 and event handlers.
3) determine the document's size and set the positioning accordingly, something like:
centerY = window.innerHeight / 2;
centerX = window.innerWidth / 2;
If you know the height & width of the div, you can then use the center to determine the offsets.
lPosition = centerX + (divWidth/2);
tPosition = centerX + (divHeight/2);
...style="position:absolute; top:" + tPosition + ";left:" + lPosition .....

Hope this helps
Vinny

Where the world once stood
the blades of grass cut me still

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Wow Vinny, that was quick.

I'm sorry to say but:
I can't use #1 because of the NN4-problem.
I can't use #2 because the is more than text. It contains rollover images etc as well.

But, to cheer you up:
I can use #3!!!! Hooray!!
Little bit dumb of me not coming up with that (...)
I'm aware of the fact that I have to deal with the users different resolutions, but to solve that little problem shouldn't be too much.

Thanks!

Shakespeare: onclick || !(onclick)

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Jack,

Hey one out of three -- not bad Smiling
Glad you think it's not much work. Smiling

Vinny

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.