Jump to content

css sticky footer main div height


arbitter

Recommended Posts

Hi there.

 

The title might be somewhat confusing, but here's the explanation. My site consists of the following layout:

  • Header
  • Left sidebar
  • Main content
  • Footer

 

This I've got working nicely with the following code:

HTML:

<html>
   <body>
      <div id='total'>
         <div id='wrap'>
            <div id='banner'></div>
            <div id='main'>
               <div id='sidebar'>
                  <div class='menuoption'></div>
                  <div class='menuoption'></div>
                  <div class='menuoption'></div>
                  <div id='leftFill'></div>
               </div>
               <div id='content'>Variable content over here</div>
            </div>
         </div>
         <div id='footer'></div>
      </div>
   </body>
</html>

And the css:

html{height:100%;}
body{
   margin:0 0 0 0;
   height:100%;
}
#total{
   width:1024px;
   margin:auto;
   height:100%;
}
#wrap{
   min-height:100%;
}
#main{
   overflow:auto;
   padding-bottom:28px;   /* Height of footer */
}
#header{
   height:100px;
   background-color:purple;
}
#sidebar{
   width:149px;
   float:left;
   height:100%;
}
#content{
   width:794px;
   float:left;
   min-height:600px;
}
#footer{
   height:28px;
   margin-top: -28px;
   clear:both;
   position:relative;
}

 

So what's happening: the footer should always be at the bottom of the page, as long as the content inside #content is not larger than the height of the page. Otherwise, the footer goes to the foot of the document.

 

Now the trouble is; I would like the #leftFill to have  a border on the right side. But this bordershoul go from the last 'menuoption' down, up to the footer, wherever the footer is. How is this done?

Link to comment
https://forums.phpfreaks.com/topic/265301-css-sticky-footer-main-div-height/
Share on other sites

Instead

You can float both sidebar and content divs left, removing the min-height,

then apply a clearfix on the footer

 

Maybe then re-apply the leftFill height of 100%

They are both already floated left, and there is 'clear:both' in the footer already...

played around with and go sourted replace your code with this one.

 

 <div id='total'>
         <div id='wrap'>
            <div id='banner'></div>
            <div id='main'>
               <div id='sidebar'>
                  <div class='menuoption'>gggg</div>
                  <div class='menuoption'>hhhh</div>
                  <div class='menuoption'></div>
                  <div id='leftFill'></div>
               </div>
               <div id='content'>
                 <p>Variable content over herei</p>
                 <p> </p>
                 <p> </p>
                 <p> </p>
                 <p> </p>
               </div>
               <div style="clear:both";></div>
            </div>
         </div>
         <div id='footer'></div>
      </div>

 

 

html{height:100%;}
body{
   margin:0 0 0 0;
   height:100%;
}
#total{
   width:1024px;
   margin:auto;
   height:100%;
}
#wrap{
   
}
#main{
   overflow:auto;
   padding-bottom:28px;   /* Height of footer */
}
#header{
   height:100px;
   background-color:purple;
}
#sidebar{
   width:149px;
   float:left;
   height:100%;
}
#content{
   width:794px;
   float:left;
   min-height:60%;
}
#footer{
   height:28px;
   margin-top: 2px;
   clear:both;
   position:relative;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.