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

  • Home
  • SEARCH
  • 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 6709797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:55:29+00:00 2026-05-26T07:55:29+00:00

The Background: I tried to solve the StackOverflow question yet another HTML/CSS layout challenge

  • 0

The Background:

I tried to solve the StackOverflow question yet another HTML/CSS layout challenge – full height sidebar with sticky footer on my own using jQuery. Because the sidebar in my case may be longer than the main content it matches the case of comment 8128008. That makes it impossible to have a sidebar longer than the main content and having a sticky footer without getting problems when shrinking the browser window.

The status quo:

I have a html page with a div, which is automatically stretched to fill the screen. So if there is empty space below the element, I stretch it downwards:

The div is stretched to fill the screen

But if the browser viewport is smaller than the div itself, no stretching is done but the scrollbar shows up:

Small viewport: no resizing

I’ve attached jQuery to the window’s resize event to resize the div, if the browser window is not to small and remove any resizing in the other case. This is done by checking if the viewport is higher or smaller than the document. If the viewport is smaller than the document, it seems like the content is larger than the browser window, why no resizing is done; in the other case we resize the div to fill the page.

if ($(document).height() > $(window).height()) {
    // Scrolling needed, page content extends browser window
    // --> No need to resize the div
    // --> Custom height is removed
    // [...]
} else {
    // Window is larger than the page content
    // --> Div is resized using jQuery:
    $('#div').height($(window).height());
}

The Problem:

Up to now, everything runs well. But if I shrink the browser window, there are cases, where the div should be resized but the document is larger than the window‘s height, why my script assumes, that no resizing is needed and the div‘s resizing is removed.

The point is actually, that if I check the document‘s height using Firebug after the bug appeared, the height has just the value is was meant to have. So I thought, the document‘s height is set with a little delay. I tried to run the resize code delayed a bit but it did not help.

I have set up a demonstration on jsFiddle. Just shrink the browser window slowly and you’ll see the div “flickering”. Also you can watch the console.log() output and you will notice, that in the case of “flickering” the document‘s height and the window‘s height are different instead of being equal.

I’ve noticed this behavior in Firefox 7, IE 9, Chrome 10 and Safari 5.1. Can you confirm it?

Do you know if there is a fix? Or is the approach totally wrong? Please help me.

  • 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-26T07:55:29+00:00Added an answer on May 26, 2026 at 7:55 am

    Ok — wiping my old answer and replacing…

    Here’s your problem:

    You are taking and comparing window and document height, without first taking into consideration the order of events here..

    1. Window loads
    2. Div grows to window height
    3. Window shrinks
    4. Document height remains at div height
    5. Window height is less than div height

    At this point, the previously set height of the div is keeping document height greater than the window height, and this logic is misinterpreted:
    “Scrolling needed, no need to extend the sidebar” fires, erroneously

    Hence the twitch.

    To prevent it, just resize your div along with the window before making the comparison:

    (function () {
        var resizeContentWrapper = function () {
                console.group('resizing');
    
    
                var target = {
                    content: $('#resizeme')
                };
    
                //resize target content to window size, assuming that last time around it was set to document height, and might be pushing document height beyond window after resize
            //TODO: for performance, insert flags to only do this if the window is shrinking, and the div has already been resized
                target.content.css('height', $(window).height());
    
                var height = {
                    document: $(document).height(),
                    window: $(window).height()
                };
    
                console.log('height: ', height);
    
    
                if (height.document > height.window) {
                    // Scrolling needed, no need to externd the sidebar
                    target.content.css('height', '');
    
                    console.info('custom height removed');
                } else {
                    // Set the new content height
                    height['content'] = height.window;
                    target.content.css('height', height['content']);
    
                    console.log('new height: ', height);
                }
                console.groupEnd();
            }
        resizeContentWrapper();
        $(window).bind('resize orientationchange', resizeContentWrapper);
    })(jQuery);
    

    Per pmvdb’s comment, i renamed your $$ to “target”

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

Sidebar

Related Questions

I am from a MSSQL Server background and tried to search to see if
I tried to set the background color of a data grid view to be
I tried something like this but it just makes the background of the image
How to change cell background image on click on cell in iphone????I have tried
It seems like a trivial problem, but nothing I've tried will make the background
I have tried a few things to solve this problem but I can't seem
I've been looking at the css code for quite a while and have tried
I have a two column layout: <html> <head></head> <body> <div id=container> <div id=header></div> <div
I have an image.png with white background and some trasparceny over it. I tried
I tried a lot to add the font size , text color and background

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.