Created
May 25, 2012 00:47
-
-
Save jimmynotjim/2785129 to your computer and use it in GitHub Desktop.
jQuery script to equalize the sidebar and content of a page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simple jQuery script to set a sidebar to always span the height of a page. Required when the sidebar has a background, borders, or shadows. #main is the container for both the sidebar and content and can be replaced w/ any other element. It's important to use min-height, in case your sidebar has moving/changing elements that could resize it larger than the main content (or just happens to be larger than the main content). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set #sidebar's min-height equal to height of #main element | |
//-------------------------------------------------------- | |
function equalHeight() { | |
$('#sidebar').css( 'min-height', $('#main').height() ); | |
} | |
// Runs the script when the page loads | |
//-------------------------------------------------------- | |
equalHeight(); | |
// Added a resize event to #main that fires the script anytime the container is resized | |
//-------------------------------------------------------- | |
$('#main').resize(function() { | |
equalHeight(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set the script as a function so that I could fire it again when the #main element is resized (using https://github.com/cowboy/jquery-resize). Required when using iframes like w/ Facebook widgets, Wufoo forms, or other external data that loads after the height has been calculated.