JavaScript
Article
By Sam Deering

jQuery Set Minimum Height for Page Content

By Sam Deering
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

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.

--ADVERTISEMENT--

//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
}
Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?