Created
November 29, 2012 03:31
-
-
Save jdlich/4166622 to your computer and use it in GitHub Desktop.
Dynamic height sticky footer
This file contains hidden or 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
<html> | |
<head> | |
<!--[if !IE 7]> | |
<style type="text/css"> | |
.wrapper { | |
display: table; | |
height: 100% | |
} | |
</style> | |
<![endif]--> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<div class="container"> | |
<!-- content --> | |
</div> | |
</div> | |
<footer></footer> | |
</body> | |
</html> |
This file contains hidden or 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
(function () { | |
$(document).ready(function() { | |
setFooterHeight(); | |
}); | |
$(window).resize(function() { | |
setFooterHeight(); | |
}); | |
function setFooterHeight() { | |
var container = $(".container"), | |
footer = $("footer"), | |
overlap = 25, | |
footerHeight = $(window).height() - container.height(), | |
totalHeight = footerHeight + overlap; | |
if ( footerHeight < 0 ) { | |
footer.css({ | |
"margin-top" : -overlap | |
}); | |
} else { | |
container.css({ | |
"padding-bottom" : footerHeight | |
}); | |
footer.css({ | |
"margin-top" : -totalHeight, | |
"height" : totalHeight | |
}); | |
} | |
} | |
})(); |
This file contains hidden or 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
html, body { | |
height: 100%; | |
} | |
.wrapper { | |
min-height: 100%; | |
} | |
.container { | |
overflow: auto; | |
/* padding-bottom: x */ | |
} | |
footer { | |
position: relative; | |
clear: both; | |
/* height: x */ | |
/* margin-top: -x */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment