Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:54:03+00:00 2026-05-25T09:54:03+00:00

I need a sidebar div and a content div with a height that is

  • 0

I need a sidebar div and a content div with a height that is always 100% of the container height, regardless of the content. The container size changes when the window size changes. I can’t use a background to fake the effect. I have to design for IE6 and decided to use Javascript to try and come up with a cross-browser solution.

Basically, when the page is loaded, a function finds the offsetHeight of the container, subtracts the offsetHeight of the header, and sets the style.height of the sidebar and content div equal to the result.

Because of an infinite loop bug in IE6 I had to implement a function that checks if the window has actually been resized.

It works fine in FF (Actually, I got the effect I wanted in FF without any Javascript at all, but I digress…), but in IE6 the content div actually increases in size on each resize event. It increase in height by exactly 6 pixels.

Edit: I wanted to add that the code actually works fine when increasing the size of the window, but not when decreasing the size of the window.

Here’s a link to the fiddle: Here

The Javascript:

var setup = {
viewWidth: undefined,
viewHeight: undefined,
newViewWidth: undefined,
newViewHeight: undefined,
resizeTimeout: undefined,

findView: function() {
    if (typeof window.innerWidth != 'undefined') {
        viewWidth = window.innerWidth;
        viewHeight = window.innerHeight;
    }

    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewWidth = document.documentElement.clientWidth;
        viewHeight = document.documentElement.clientHeight;
    }
},

windowCheck: function() {

    setup.findView();

    if (setup.viewWidth != setup.newViewWidth || setup.viewHeight != setup.newViewHeight) {
        setup.resizeTimeout = window.setTimeout(setup.onResize, 10);
    };


},

 onResize: function() {
    var head = document.getElementById("viewportheader").offsetHeight;
    var content = document.getElementById("container").offsetHeight;



    document.getElementById("listing").style.height = content - head + 'px';
    document.getElementById("viewport").style.height = content - head + 'px';

    document.getElementById("tester2").innerHTML = content;
    document.getElementById("tester").innerHTML = content - head;


    setup.newViewWidth = document.documentElement.clientWidth;;
    setup.newViewHeight = document.documentElement.clientHeight;

    window.clearTimeout(setup.resizeTimeout);
 }
};


function start() {
    setup.onResize();
    window.onresize = resize;

}

function resize() {
    setup.windowCheck();
}

window.onload = start;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:54:05+00:00Added an answer on May 25, 2026 at 9:54 am

    EDIT: Here’s an even easier solution!

    With the elements you’re calculating the heights from (#viewportheader, #container), just set their overflow properties to hidden (overflow: hidden;). This will make them ignore the sizes of its children and just resize to its parent width/height.

    — Alternative solution —

    onResize: function() {
        // You need to reset the heights before you do your calculations
        document.getElementById("listing").style.height = '0px';
        document.getElementById("viewport").style.height = '0px';
    
        var head = document.getElementById("viewportheader").offsetHeight;
        var content = document.getElementById("container").offsetHeight;
    
    
        document.getElementById("listing").style.height = content - head + 'px';
        document.getElementById("viewport").style.height = content - head + 'px';
    
        document.getElementById("tester2").innerHTML = content;
        document.getElementById("tester").innerHTML = content - head;
    
        // IE uses offsetWidth/Height, you'll need to check for this
        setup.newViewWidth = document.documentElement.offsetWidth;
        setup.newViewHeight = document.documentElement.offsetHeight;
    
        window.clearTimeout(setup.resizeTimeout);
    }
    

    There are a few problems that add together to Actually after testing, you only have one problem creates this issue in IE6.

    When a div has a width or height to 100%, it also takes into consideration it’s children. If, say, the width of the document was calculated at 100px, and the div’s width was set to 100%, then the div’s calculated width is 100px too. But if you have resized it’s children to 100px too, then resize the document to 80px, even though the div’s width is set to 100%, it will still stay as 100px and not resize to 80px. This is because it’s children are larger than 80px, as so the div will resize to fit it’s children.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to load content while scrolling a div , not window. That's my
Hi I have a simple sidebar inside a div which has height:100% and I
i have following HTML structure: <div class=container> <div class=sidebar></div> <div class=content></div> <div class=subscript></div> </div>
I have the following html structure: <div class=container> <div class=header></div> <div class=sidebar></div> <div class=content-loading></div>
My main div .container is set to overflow:hidden; to maintain 100% height, it nests
Everything's explained in the above image. Basically, I need a sidebar div whose width
I need that when I scroll down or up with mouse wheel or sidebar
Think that you have a content div whether the content of a website is
On my page I have a content div that only shows when the mouse
I am in need of a css layout for fixed size sidebar and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.