<html>
<style>
header, footer {
position: fixed;
left: 0;
right: 0;
height: 100px;
background: teal;
}
header {
top: 0
}
footer {
bottom: 0
}
.content {
position: fixed;
top: 100px;
bottom: 100px;
left: 0;
right: 0;
overflow-y: scroll;
}
.container {
padding: 20px;
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
</style>
<header></header>
<div id="content_id" class="content">
<div class="container">Just
<br>Some
<br>Text.
<br>
<br>Try
<br>resizing
<br>the
<br>height
<br>of
<br>the
<br>window</div>
</div>
<footer></footer>
var $content = $('.content'),
$container = $('.container'),
containerHeight = $container.outerHeight();
$(window).resize(function () {
$container.css({
position: $content.innerHeight() > containerHeight ? 'absolute' : 'static',
});
$content.scrollTop($container.height());
}).resize();
</html>
相关地址: http://jsfiddle.net/4LQnW/6/