DIV tags and style=" ... " attributes

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, Folks.

I am trying to figure out how to get a DIV layer to appear in the middle of
a web page.  I would like it to be a bit dynamic so that it would
recalculate its position if the browser window is resized.

I am thinking of something like:

style = "TOP: (window.innerHeight - this.height)/2; LEFT:
(window.innerWidth - this.width)/2;"

What entries or variables would I use inside of style = " ... "?

Is this even possible?


Re: DIV tags and style=" ... " attributes

Quoted text here. Click to load it

If you wanted to get specific with JavaScript, you could specify something

    top:expression((window.innerHeight - this.height)/2 + "px");
    left:expression((window.innerWidth - this.width)/2 + "px");

but that would only work in IE4+ and only if JavaScript was enabled. Also, I
think you'd get CSS validation errors because expression() is only specific
to IE.

The alternative is to forget about getting it vertically aligned and just


This will center it horizontally.


Site Timeline