Results 1 to 2 of 2

Thread: DIV resizing issue

  1. #1
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DIV resizing issue

    I would like my div container's height to automatically resize with the content that is added dynamically or dragged & dropped into it. I couldnt figure out the proper CSS without using fixed height and a scrollbar that I don't want. I tried using javascript to resize the container when new content is added to it but the scrollHeight always gets larger & larger even as I remove content. Here is my JS function, is there a better property I could use to determine:

    1. If the content area of the div container is larger than the client window then resize the container to be the size of the content area else resize the container to be the size of the client window


    function resize(){
    var htmlheight = document.body.parentNode.scrollHeight;
    var windowheight = document.body.parentNode.clientHeight;
    var containerDiv = document.getElementById(containerId);


    if ( htmlheight < windowheight ) {
    containerDiv.style.height = windowheight + "px";
    }
    else {
    containerDiv.style.height = htmlheight + "px";
    }
    }

  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

    If you have a free standing division with a width, but no height specified, its height will automatically adjust to whatever content is placed inside of it, up to 100% of the height of any container it may be inside of.
    - 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
  •