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
}

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

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