DIV tags and style=" ... " attributes

E

Eeediot

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?

TIA
 
E

e n | c k m a

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.

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

div{
position:absolute;
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
use:

div{width:80%;margin:auto}

This will center it horizontally.

HTH,
Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top