0

I have the page layout with footer still at the bottom of the page. The problem is when I use some divs with content which are FLOAT. If I ommit the float then the content behaves properly and does not overflow the footer. Please see:

`enter code here`
http://jsfiddle.net/8o7t4wq9/1/


CSS:
html,
body {
   margin:0;
   padding:0;
   height:100%;
}
#container {
   min-height:100%;
   position:relative;
}
#header {
   background:#ff0;
   padding:10px;
}
#body {
   padding:10px;
   padding-bottom:60px;   /* Height of the footer */
}
#footer {
   position:absolute;
   bottom:0;
   width:100%;
   height:60px;   /* Height of the footer */
   background:#6cf;
}

HTML:
<div id="container">
   <div id="header"></div>
   <div id="body">
       <div style="width:100%;min-height:500px;background-color:gray;clear:both;">IMAGES</div>
       <div style="width:30%;min-height:1500px;margin:5px;background-color:green;float:left">First box of content</div>
       <div style="width:30%;min-height:1500px;margin:5px;background-color:green;float:left">Second box of content</div>
   </div>
   <div id="footer">FOOTER</div>
</div>
Lukáš Ježek
  • 75
  • 3
  • 11

4 Answers4

0
#footer {
   position:absolute;//remove
   bottom:0;//remove
   width:100%;
   height:60px;   /* Height of the footer */
   background:#6cf;
    clear:both;//add
}
madalinivascu
  • 32,064
  • 4
  • 39
  • 55
0

Try to add a parent div to your floated divs and add clearfix to the parent.

html,
body {
   margin:0;
   padding:0;
   height:100%;
}
#container {
   min-height:100%;
   position:relative;
}
#header {
   background:#ff0;
   padding:10px;
}
#body {
   padding:10px;
   padding-bottom:60px;   /* Height of the footer */
}
#footer {
   position:absolute;
   bottom:0;
   width:100%;
   height:60px;   /* Height of the footer */
   background:#6cf;
}

.clearfix:after {
 visibility: hidden;
 display: block;
 font-size: 0;
 content: " ";
 clear: both;
 height: 0;
 }
<div id="container">
   <div id="header"></div>
   <div id="body">
       <div style="width:100%;min-height:500px;background-color:gray;clear:both;">IMAGES</div>
       <div class="clearfix">
           <div style="width:30%;min-height:1500px;margin:5px;background-color:green;float:left;">First box of content</div>
           <div style="width:30%;min-height:1500px;margin:5px;background-color:green;float:left;">Second box of content</div>
       </div>
   </div>
   <div id="footer">FOOTER</div>
</div>
Roi
  • 503
  • 1
  • 12
  • 25
  • Great, thanks a lot, it works fine now (regarding the advice to remove the absolute position, I could not do that because if the content was shorter than the height of the page, then the footer would not sit down, but thanks anyway) – Lukáš Ježek Jun 17 '15 at 12:04
0

It's hard to pinpoint/see your problem widouth fiddle, but you should probably look at css clearfix

Add css class(clearfix) to containers

.clearfix:after{
    content: "";
    display:table;
    clear:both;
} 

for more info and cros browser support look at this thread What is a clearfix?

Community
  • 1
  • 1
Matej Žvan
  • 758
  • 4
  • 13
-1

Remove position:absolute and bottom:0 from footer and add clear:both.

#footer {
   width:100%;
   height:60px;
   background:#6cf;
   clear:both;
}

Read More

099
  • 333
  • 1
  • 15