How to set footer position absolute or relative depending on content size?
I want to do something like this:
In case 1: content height is smaller than window. In case 2: content height is larger than window - and scroll shows,
My problem is that content is dynamically changed. So, sometimes .cont height is larger than wind开发者_开发知识库ow height. And then, .foot should be beneath of .cont.
If I set this code
<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>
I get this:
If you can modify the markup slightly, try Ryan Fait's Sticky Footer approach:
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}
<div class="wrapper">
<p>Your website content here.</p>
<div class="push"></div>
</div>
<div class="footer">
<p>Copyright (c) 2008</p>
</div>
On his website, he mentions the code solution is free to use without license.
精彩评论