Forum Moderators: open

Message Too Old, No Replies

Aligning a DIV element at the center of page.

how to align a div element on a client website

         

israr

3:41 pm on Oct 10, 2008 (gmt 0)

10+ Year Member



Hi all,
I need to align a div element on the center of screen/page using javascript. Here is complete problem:

I have website which provides rss based ticker headline news to client sites. i.e. a client paste's my code on his site to display news marquee from my site. eg.

<script language='javascript' src='http://www.mysiteurl.com/ticker.html'></script>

Now when the user click's a news headline (title part of rss feed), the detail is shown (description part of feed), I want this description inside a div element at the center of page.

I have tried many common javascript methods to align the div at center but they dont work, when you have hotlinked your code (i.e. div is not centered on client site's page/screen).

Note that on google's igoogle page if you use the Google Reader gadget, it does the same functionality...

Does anybody has a suggestion.

httpwebwitch

8:50 pm on Oct 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var wh = height of the user's window
var ww = width of user's window
var dh = height of div
var dw = width of div

div.style.top = (wh/2-dh/2)
div.style.left = (ww/2-dw/2)

div.style.position = 'fixed'

israr

4:06 am on Oct 12, 2008 (gmt 0)

10+ Year Member



Thanks, its working for IE, firefox...