Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - HELP!: find window width? Center a <div>?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedHELP!: find window width? Center a <div>?

 Post Reply Post Reply
Author
Kingherc View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 30 April 2003
Status: Offline
Points: 7
Direct Link To This Post Topic: HELP!: find window width? Center a <div>?
    Posted: 05 July 2003 at 5:07pm

Well here's my problem (a JavaScript problem i think):

I have a <div> on my page. I want that div to be shown over the document. But I also want the div to be in the exact center of the page or it won't look right.

I have tried many things, and played with the css styles of the position (top & left attributes). For a minute i got stuck on the ''left'' css attribute. The brightest solution was to enter 50% in the attribute but unfortunately that applies only to the edge, so the width exceeds the center and it doesn't look right again! I have the div's width but I don't know (well i don't know if it CAN happen) how to subtract it from a percantage like 50%-width would be great!

The next idea was to divide the window's width by two and then subtract the half of the div's width. But again, the window's width can only be determined in Netscape. In Internet Explorer I can't seem to find a way to find the window's width through JavaScript. Can anyone plz tell me how to find it??

(and my last solution was to put it inside the <center></center>, but that works only when the <div> is part of the document layer, which doesn't make it float over the document and, so, still doesn't seem right!)

Anyway, can anyone show me how to find the window's width in Internet Explorer or better yet how to center a ''floating'' div?? Thx 4 all responsed!!

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Direct Link To This Post Posted: 05 July 2003 at 7:28pm
why not use <div align=center> to center the div?
Back to Top
Kingherc View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 30 April 2003
Status: Offline
Points: 7
Direct Link To This Post Posted: 05 July 2003 at 11:42pm
Well I think that works only for the text inside the <div>.
Back to Top
Bluefrog View Drop Down
Senior Member
Senior Member


Joined: 23 October 2002
Location: Korea, South
Status: Offline
Points: 1701
Direct Link To This Post Posted: 09 July 2003 at 9:33am
Check out some DHTML sites. There are some scripts that have drop in DHTML DIVs that can be configured to do the same thing. i.e. google for "DHTML DIV drop in" or something like that.
Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Direct Link To This Post Posted: 14 July 2003 at 2:59pm

http://www.javascripter.net/faq/browserw.htm

This will tell you how to get the window size and width using javascript. From there you can maybe use an absolute position to put the div directly in the center of the page. Although the easiest way of doing this would be to make a table and just use the standard align and size properties of the table to get it adjusted where you want it, and put the div inside of the table then.

- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
Bluefrog View Drop Down
Senior Member
Senior Member


Joined: 23 October 2002
Location: Korea, South
Status: Offline
Points: 1701
Direct Link To This Post Posted: 14 July 2003 at 10:34pm

I saw this script used in one place today and remembered this thread:

<script language="Javascript"><!--

if (self.screen) {    
        width = screen.width
        height = screen.height
}

// for NN3 w/Java
else if (self.java) {  
       var javakit = java.awt.Toolkit.getDefaultToolkit();
       var scrsize = javakit.getScreenSize();      
       width = scrsize.width;
       height = scrsize.height;
}
else {

// N2, E3, N3 w/o Java (Opera and WebTV)
width = height = '?'
}

document.write("Your Screen Resolution is set to: "+ width +" x "+ height)
     
//-->
</script>

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.