JavaScript
Article

jQuery Set Minimum Height for Page Content

By Sam Deering

jQuery code snippet which set a minimum height for a page content area based on the size of the window. This could be used to set the footer of a page to always be on the bottom within the page content area no matter what size the window is. It could be used with Capturing window resize so that it resizes automatically when the user resizes the browser window.

//sets the minimum height for the content area of the page
minWrapperHeight: function()
{
    var wrapperElem = $('#wrapper');
    //padding+offset+header+footer
    var offset = wrapperElem.height()-wrapperElem.outerHeight()-$('header').height()-$('footer').height()-$('#wrapper').offset()['top'];
    console.log($(window).height() + ' - ' + offset + ' = ' + ($(document).height()-offset));
    wrapperElem.height($(window).height()+offset); //offset is negative
}

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.