enloz enloz - 3 years ago 134
CSS Question

CSS: footer position absolute or relative depending on content size?

I want to do something like this:
enter image description here

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 window 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:
enter image description here

Thanks for any help!

Answer Source

If you can modify the markup slightly, try this: http://ryanfait.com/sticky-footer/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download