html - Site min-height 100% -


i'm building website want have minimum height of 100%, if there's not content on page, footer @ bottom of page. if there's more content, expand.

i used website has example, , changed needs.
@ first seemed work great, it's showing 2 problems:
- site seems bit more 100% height; small part extends beyond screen.
- footer isn't displayed @ bottom, rather somewhere in middle, despite having set bottom property.

this markup:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <%@ master language="vb" codefile="site.master.vb" inherits="site" %>  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">     <head id="head" runat="server">         <meta http-equiv="x-ua-compatible" content="ie=emulateie9">         <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />         <title>site (b&egrave;ta)</title>     </head>     <body>         <form id="form1" runat="server" autocomplete="off" class="formcss">             <ajax:toolkitscriptmanager id="toolscriptmanager1" runat="server" enablescriptglobalization="true" enablescriptlocalization="true">                 <scripts>                     <asp:scriptreference path="~/js/jquery-1.8.2.min.js" />                     <asp:scriptreference path="~/js/jquery.curvycorners.packed.js" />                     <asp:scriptreference path="~/js/site.jquery.js" />                     <asp:scriptreference path="~/js/jquery.colorize-1.3.1.js" />                 </scripts>             </ajax:toolkitscriptmanager>             <asp:label id="contenttitle" runat="server" cssclass="content_title"></asp:label>             <div id="container">                 <div id="headercontainer">                     <div id="header">                         <telerik:radmenu id="hoofdmenu" enableembeddedskins="false" height="20px" enableimagesprites="false" font-size="11px" runat="server" collapsedelay="0" expanddelay="0" clicktoopen="true" expandanimation-type="none" collapseanimation-type="none" causesvalidation="false"></telerik:radmenu>                     </div>                 </div>                  <div id="content">                     <asp:contentplaceholder id="content" runat="server"></asp:contentplaceholder>                 </div>                 <div id="footer">                     footer                 </div>             </div>        </form>     </body> </html> 

this css:

html,body  {     margin:5px;     padding:0;     height:100%; /* needed container min-height */       font-family:tahoma;     font-size:11px;     color:#000000;     background-color: #8fb1b1;       /*background-image: url(../../images/afbeelding1.jpg);*/ }  .formcss {     height:100%;     min-height: 100%; }  div#container  {     position:relative; /* needed footer positioning*/     margin:0 auto; /* center, not in ie5 */     width:100%;          height:auto !important; /* real browsers */     height:100%; /* ie6: treaded min-height*/     min-height:100%; /* real browsers */      background-color: #ffffff;   }  div#headercontainer {     background-color: #8fb1b1; } div#header  {     padding-left:5px;     padding-top: 12px;       height: 30px;        background-color: #1c2948;  /*#833d62;*/     z-index: 100; }   div#content  {     padding-left: 10px;     padding-right: 10px;     padding-top:10px;        background-color: #ffffff; /* #e0e5d7; #ffffff;*/     padding-bottom:25px;  /* bottom padding footer */      /*filter:alpha(opacity=80);      -moz-opacity:0.80;      opacity:0.80;   */  }     div#footer  {     position:absolute;     height: 25px;        bottom:0; /* stick bottom */     background:#ffffff;          padding-left: 10px; }    

i have put code in fiddle: http://jsfiddle.net/7uud6/1
(it contains asp.net code jsfiddle can't handle, unfortunately)

what doing wrong? cheers, cj

there 2 methods use maintain sticky footer, depend on browser support though.

if not care ie7 or firefox versions earlier 17 can use approach uses box-model border-box property.

border-box version

for need 2 elements.

html

<div class="page">     </div>  <div class="page-footer"> </div> 

css

*, *:before, *:after {     /* fix box model include padding */     -webkit-box-sizing: border-box;     -moz-box-sizing: border-box;     -ms-box-sizing: border-box;     box-sizing: border-box; }  html, body {     height: 100%;     margin: 0;     position: relative; }  .page {     min-height: 100%;     position: relative;     margin-bottom: -150px;     padding-bottom: 150px; }  .page-footer {     height: 150px;     position: relative;     z-index: 1; } 

if need support older browsers need use div push footer down.

legacy version

the code need version follows.

html

<div class="page">     <div class="page-push">         <!--             div pushes footer down content not overflow         -->     </div> </div>  <div class="page-footer"> </div> 

css

html, body {     height: 100%;     margin: 0;     position: relative; }  .page {     min-height: 100%;     position: relative;     margin-bottom: -150px; }  .page-push, .page-footer{     height:150px; }  .page-footer {     position: relative;     z-index: 1; } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -