Forum Moderators: open

Message Too Old, No Replies

how to center a frame from all direction in a page

         

IT_Master

2:50 pm on May 18, 2004 (gmt 0)

10+ Year Member



Deal all

I would like to ask if it possible through javascript to center a frame for all directions and be in the middle of the page all the time even if someone sesize the browser window. Thank you in advance

crashomon

3:13 pm on May 18, 2004 (gmt 0)

10+ Year Member



Why use Javascript? You might be able to get away with using CSS (less scripting...)

But generally, Javascript uses h/2 and w/2 (height and width divided by half) to find 'center point.'

The trick would then be to have it adjust for the height/width of the frame (if its 300 wide, to adjust for +-150 to perfectly center it).

But, seriously, consider using a centered DIV and your frame should show up nicely within that.

At least, thats how I would approach it . . . .

Good luck,

Patrick Elward

Also, check Google for javasript +frames +center and see what you get

IT_Master

4:01 pm on May 18, 2004 (gmt 0)

10+ Year Member



Why use Javascript? You might be able to get away with using CSS (less scripting...)

>I have to place the webpage exactly in the middle from all directions(top,bottom,left,right) and i think that if you want to do that for 120 different pages i have it is going to take loads of time.

But generally, Javascript uses h/2 and w/2 (height and width divided by half) to find 'center point.'

The trick would then be to have it adjust for the height/width of the frame (if its 300 wide, to adjust for +-150 to perfectly center it).

>The dimensions of the frame are pre-set to 800x600

But, seriously, consider using a centered DIV and your frame should show up nicely within that.

>That is what i am using at the moment...although it does not space equally from top and bottom...only from left and right.
Also, check Google for javasript +frames +center and see what you get

>I have done that already and it comes up with how to center a pop-up windo. I am wondering if we can use the same principal for the frame.

Thank you for the time you took to look into the question.

crashomon

5:16 pm on May 18, 2004 (gmt 0)

10+ Year Member



>>>>>>That is what i am using at the moment...although it does not space equally from top and bottom...only from left and right.

Well, if you use "padding" you can force it to push down 300 pixels or whatever from the top and you can't control how far down the window is going to open (unless you do the popup window as you mentioned).

thats another way to make it 'appear' in the middle.

sorry I can't be of more use.

Patrick Elward

IT_Master

8:16 am on May 19, 2004 (gmt 0)

10+ Year Member



Thank you for all the time you spent to look at my question....the padding thing is going to give the illussion that is centered although it is not going to be. The policy of the board is not to have any kind of links on post so i will mail you the link so you are going to have a better understanding what i am talking about.

[edited by: korkus2000 at 3:28 pm (utc) on May 19, 2004]
[edit reason] edited typo [/edit]

Rambo Tribble

3:46 pm on May 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Vertical centering is a bit of a problem, judging from everything I have encountered. While it is possible to derive the center of the screen with availHeight, I know of no similar function to determine the height of the browser window or page display area. I believe the only work-around would be to open your own window, with its height and width specified, so you have known values to start from.

That said, it occurs to me that it might be possible (though I'm skeptical) to set a div to 100% height, then read its vertical dimension by querying its CSS properties. I'll try to give that approach some investigation this evening, when I get home from work.

[edited by: korkus2000 at 3:52 pm (utc) on May 19, 2004]
[edit reason] Removed off topic chatter [/edit]

DrDoc

3:53 pm on May 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you talking about a frame, or an iframe?
If it's an iframe, you can position the iframe element absolutely using CSS. All you need to know is the height and width. Here's a tutorial:

[wpdfd.com...] (navigation at the bottom of the page)

IT_Master

4:29 pm on May 19, 2004 (gmt 0)

10+ Year Member



This is very helpful.Thank you.do you know if i can replace the box in the middle with an frame or iframe?

DrDoc

4:34 pm on May 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not a frame, but an iframe (or whatever else you would like) should work...