Results 1 to 2 of 2

Thread: Setting a division's height based on Screen Height.

  1. #1
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Setting a division's height based on Screen Height.

    --------------------------------------------------------------------------------

    I'm needing to resize a <div> based on the height of a users screen, relative heights in css are not cutting the mustard.

    What I would like is code to place in an external .js file that would detect the screen height, and By the elements ID set the height. I believe this would be the best way, if I am wrong, let me know, I need to know the best way to do this.

    As always, dd community, thanks for all the help in advance!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    What if the browser is only occupying a small portion of the user's screen? In those situations do you still want to size the division relative to the user's screen height? In any case, if this is what you truly want to do:

    Code:
    document.getElementById('divId').style.height=screen.height+'px'
    or for only a portion of the screen height:

    Code:
    document.getElementById('divId').style.height=screen.height*0.9+'px'
    You can put this in an external .js file say - div_height.js and call it on your page just above the closing </body> tag:

    HTML Code:
    <script src="div_height.js" type="text/javascript"></script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •