我想做这样的事情:

在案例1中:内容高度小于窗口.在案例2中:内容高度大于窗口 - 并滚动显示,
我的问题是内容是动态变化的.因此,有时.cont高度大于窗口高度.然后,.foot应该在.cont之下.
如果我设置此代码
<html>
<head>
<style type="text/css">
.cont{
margin:0 auto;
background-color:#333;
width:800px;
height:500px;
}
.foot {
position:absolute;
left:50%;
margin:0 0 0 -400px;
background-color:#F33;
width:800px;
height:20px;
bottom:0px;
}
</style>
</head>
<body>
<div class="cont"></div>
<div class="foot"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我明白了:

谢谢你的帮助!
如果您可以稍微修改标记,请尝试Ryan Fait 的粘性页脚方法:
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}Run Code Online (Sandbox Code Playgroud)
<div class="wrapper">
<p>Your website content here.</p>
<div class="push"></div>
</div>
<div class="footer">
<p>Copyright (c) 2008</p>
</div>Run Code Online (Sandbox Code Playgroud)
在他的网站上,他提到该代码解决方案可以免费使用,无需许可。