<blockquote>
  <p>What's the best way to make an element of 100% minimum height across a
  wide range of browsers ?</p>
</blockquote>

<p>In particular if you have a layout with a <code>header</code> and <code>footer</code> of fixed <code>height</code>,</p>

<p>how do you make the middle content part fill <code>100%</code> of the space in between with the <code>footer</code> fixed to the bottom ?</p>

[{'answer_id': 25249, 'author': 'ollifant', 'author_id': 2078, 'author_profile': 'https://Stackoverflow.com/users/2078', 'pm_score': 7, 'selected': False, 'text': '<p>I am using the following one: <a href="http://www.xs4all.nl/~peterned/examples/csslayout1.html" rel="noreferrer">CSS Layout - 100 % height</a></p>\n\n<blockquote>\n  <p><strong>Min-height</strong></p>\n  \n  <p>The #container element of this page has a min-height of 100%. That\n  way, if the content requires more height than the viewport provides,\n  the height of #content forces #container to become longer as well.\n  Possible columns in #content can then be visualised with a background\n  image on #container; divs are not table cells, and you don\'t need (or\n  want) the physical elements to create such a visual effect. If you\'re\n  not yet convinced; think wobbly lines and gradients instead of\n  straight lines and simple color schemes. </p>\n  \n  <p><strong>Relative positioning</strong></p>\n  \n  <p>Because #container has a relative position, #footer will always remain\n  at its bottom; since the min-height mentioned above does not prevent\n  #container from scaling, this will work even if (or rather especially when) #content forces #container to become longer. </p>\n  \n  <p><strong>Padding-bottom</strong></p>\n  \n  <p>Since it is no longer in the normal flow, padding-bottom of #content\n  now provides the space for the absolute #footer. This padding is\n  included in the scrolled height by default, so that the footer will\n  never overlap the above content.</p>\n  \n  <p>Scale the text size a bit or resize your browser window to test this\n  layout. </p>\n</blockquote>\n\n<pre class="lang-css prettyprint-override"><code>html,body {\n    margin:0;\n    padding:0;\n    height:100%; /* needed for container min-height */\n    background:gray;\n\n    font-family:arial,sans-serif;\n    font-size:small;\n    color:#666;\n}\n\nh1 { \n    font:1.5em georgia,serif; \n    margin:0.5em 0;\n}\n\nh2 {\n    font:1.25em georgia,serif; \n    margin:0 0 0.5em;\n}\n    h1, h2, a {\n        color:orange;\n    }\n\np { \n    line-height:1.5; \n    margin:0 0 1em;\n}\n\ndiv#container {\n    position:relative; /* needed for footer positioning*/\n    margin:0 auto; /* center, not in IE5 */\n    width:750px;\n    background:#f0f0f0;\n\n    height:auto !important; /* real browsers */\n    height:100%; /* IE6: treaded as min-height*/\n\n    min-height:100%; /* real browsers */\n}\n\ndiv#header {\n    padding:1em;\n    background:#ddd url("../csslayout.gif") 98% 10px no-repeat;\n    border-bottom:6px double gray;\n}\n    div#header p {\n        font-style:italic;\n        font-size:1.1em;\n        margin:0;\n    }\n\ndiv#content {\n    padding:1em 1em 5em; /* bottom padding for footer */\n}\n    div#content p {\n        text-align:justify;\n        padding:0 1em;\n    }\n\ndiv#footer {\n    position:absolute;\n    width:100%;\n    bottom:0; /* stick to bottom */\n    background:#ddd;\n    border-top:6px double gray;\n}\ndiv#footer p {\n    padding:1em;\n    margin:0;\n}\n</code></pre>\n\n<p>Works fine for me.</p>\n'}, {'answer_id': 30815, 'author': 'henrikpp', 'author_id': 1442, 'author_profile': 'https://Stackoverflow.com/users/1442', 'pm_score': 4, 'selected': False, 'text': '<p>kleolb02\'s answer looks pretty good. another way would be a combination of the <a href="http://ryanfait.com/sticky-footer/" rel="noreferrer">sticky footer</a> and the <a href="http://www.dustindiaz.com/min-height-fast-hack/" rel="noreferrer">min-height hack</a></p>\n'}, {'answer_id': 42854, 'author': 'levik', 'author_id': 4465, 'author_profile': 'https://Stackoverflow.com/users/4465', 'pm_score': 3, 'selected': False, 'text': '<p>A pure <code>CSS</code> solution (<code>#content { min-height: 100%; }</code>) will work in a lot of cases, but not in all of them - especially IE6 and IE7.</p>\n\n<p>Unfortunately, you will need to resort to a JavaScript solution in order to get the desired behavior.\nThis can be done by calculating the desired height for your content <code>&lt;div&gt;</code> and setting it as a CSS property in a function:</p>\n\n<pre class="lang-js prettyprint-override"><code>function resizeContent() {\n  var contentDiv = document.getElementById(\'content\');\n  var headerDiv = document.getElementById(\'header\');\n  // This may need to be done differently on IE than FF, but you get the idea.\n  var viewPortHeight = window.innerHeight - headerDiv.clientHeight;\n  contentDiv.style.height = \n    Math.max(viewportHeight, contentDiv.clientHeight) + \'px\';\n}\n</code></pre>\n\n<p>You can then set this function as a handler for <code>onLoad</code> and <code>onResize</code> events:</p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;body onload="resizeContent()" onresize="resizeContent()"&gt;\n  . . .\n&lt;/body&gt;\n</code></pre>\n'}, {'answer_id': 2018942, 'author': 'Loaden', 'author_id': 243726, 'author_profile': 'https://Stackoverflow.com/users/243726', 'pm_score': 1, 'selected': False, 'text': '<p>You can try this: <a href="http://www.monkey-business.biz/88/horizontal-zentriertes-100-hohe-css-layout/" rel="nofollow noreferrer">http://www.monkey-business.biz/88/horizontal-zentriertes-100-hohe-css-layout/</a>\nThat\'s 100% height and horizontal center.</p>\n'}, {'answer_id': 2684612, 'author': 'MilanBSD', 'author_id': 322482, 'author_profile': 'https://Stackoverflow.com/users/322482', 'pm_score': 2, 'selected': False, 'text': '<p>Try this:</p>\n\n<pre><code>body{ height: 100%; }\n#content { \n    min-height: 500px;\n    height: 100%;\n}\n#footer {\n    height: 100px;\n    clear: both !important;\n}\n</code></pre>\n\n<p>The <code>div</code> element below the content div must have <code>clear:both</code>.</p>\n'}, {'answer_id': 5486053, 'author': 'Chris', 'author_id': 683864, 'author_profile': 'https://Stackoverflow.com/users/683864', 'pm_score': 5, 'selected': False, 'text': '<p>To set a custom height locked to somewhere: </p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>body, html {\r\n  height: 100%;\r\n}\r\n#outerbox {\r\n  width: 100%;\r\n  position: absolute; /* to place it somewhere on the screen */\r\n  top: 130px;         /* free space at top */\r\n  bottom: 0;          /* makes it lock to the bottom */\r\n}\r\n#innerbox {\r\n  width: 100%;\r\n  position: absolute;    \r\n  min-height: 100% !important; /* browser fill */\r\n  height: auto;                /*content fill */\r\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="outerbox"&gt;\r\n  &lt;div id="innerbox"&gt;&lt;/div&gt;\r\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 6870037, 'author': 'Yuda Prawira', 'author_id': 454229, 'author_profile': 'https://Stackoverflow.com/users/454229', 'pm_score': 0, 'selected': False, 'text': "<p>just share what i've been used, and works nicely</p>\n\n<pre><code>#content{\n        height: auto;\n        min-height:350px;\n}\n</code></pre>\n"}, {'answer_id': 10203133, 'author': 'Clint', 'author_id': 1340384, 'author_profile': 'https://Stackoverflow.com/users/1340384', 'pm_score': 2, 'selected': False, 'text': '<p>I agree with Levik as the parent container is set to 100% if you have sidebars and want them to fill the space to meet up with the footer you cannot set them to 100% because they will be 100 percent of the parent height as well which means that the footer ends up getting pushed down when using the clear function.</p>\n\n<p>Think of it this way if your header is say 50px height and your footer is 50px height and the content is just autofitted to the remaining space say 100px for example and the page container is 100% of this value its height will be 200px. Then when you set the sidebar height to 100% it is then 200px even though it is supposed to fit snug in between the header and footer. Instead it ends up being 50px + 200px + 50px so the page is now 300px because the sidebars are set to the same height as the page container. There will be a big white space in the contents of the page.</p>\n\n<p>I am using internet Explorer 9 and this is what I am getting as the effect when using this 100% method. I havent tried it in other browsers and I assume that it may work in some of the other options. but it will not be universal.</p>\n'}, {'answer_id': 12856368, 'author': 'Afshin Mehrabani', 'author_id': 375966, 'author_profile': 'https://Stackoverflow.com/users/375966', 'pm_score': 2, 'selected': False, 'text': '<p>First you should create a <code>div</code> with <code>id=\'footer\'</code> after your <code>content</code> div and then simply do this.</p>\n\n<p>Your HTML should look like this:</p>\n\n<pre><code>&lt;html&gt;\n    &lt;body&gt;\n        &lt;div id="content"&gt;\n            ...\n        &lt;/div&gt;\n        &lt;div id="footer"&gt;&lt;/div&gt;\n    &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>And the CSS:</p>\n\n<pre><code>\u200bhtml, body {\n    height: 100%;   \n}\n#content {\n    height: 100%;\n}\n#footer {\n    clear: both;        \n}\n</code></pre>\n'}, {'answer_id': 18486705, 'author': 'vsync', 'author_id': 104380, 'author_profile': 'https://Stackoverflow.com/users/104380', 'pm_score': 3, 'selected': False, 'text': '<p>For <code>min-height</code> to work correctly with percentages, while inheriting it\'s parent node <code>min-height</code>, the trick would be to set the parent node height to <code>1px</code> and then the child\'s <code>min-height</code> will work correctly.</p>\n\n<p><a href="http://jsbin.com/uTOwotI/1/edit"><strong>Demo page</strong></a></p>\n'}, {'answer_id': 18918955, 'author': 'Konstantin Smolyanin', 'author_id': 1823469, 'author_profile': 'https://Stackoverflow.com/users/1823469', 'pm_score': 2, 'selected': False, 'text': '<h2>Probably the shortest solution (works only in modern browsers)</h2>\n<p>This small piece of CSS makes <code>&quot;the middle content part fill 100% of the space in between with the footer fixed to the bottom&quot;</code>:</p>\n<pre><code>html, body { height: 100%; }\nyour_container { min-height: calc(100% - height_of_your_footer); }\n</code></pre>\n<p>the only requirement is that you need to have a fixed height footer.</p>\n<p>For example for this layout:</p>\n<pre class="lang-html prettyprint-override"><code>    &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;\n      &lt;main&gt; your main content &lt;/main&gt;\n      &lt;/footer&gt; your footer content &lt;/footer&gt;\n    &lt;/body&gt;&lt;/html&gt;\n</code></pre>\n<p>you need this CSS:</p>\n<pre class="lang-css prettyprint-override"><code>    html, body { height: 100%; }\n    main { min-height: calc(100% - 2em); }\n    footer { height: 2em; }\n</code></pre>\n'}, {'answer_id': 21079633, 'author': 'Fanky', 'author_id': 2095642, 'author_profile': 'https://Stackoverflow.com/users/2095642', 'pm_score': 0, 'selected': False, 'text': "<p>As mentioned in Afshin Mehrabani's answer, you should set body and html's height to 100%, but to get the footer there, calculate the height of the wrapper:</p>\n\n<pre><code>#pagewrapper{\n/* Firefox */\nheight: -moz-calc(100% - 100px); /*assume i.e. your header above the wrapper is 80 and the footer bellow is 20*/\n/* WebKit */\nheight: -webkit-calc(100% - 100px);\n/* Opera */\nheight: -o-calc(100% - 100px);\n/* Standard */\nheight: calc(100% - 100px);\n}\n</code></pre>\n"}, {'answer_id': 32027464, 'author': 'Stanislav', 'author_id': 2213164, 'author_profile': 'https://Stackoverflow.com/users/2213164', 'pm_score': 5, 'selected': False, 'text': '<p>Here is another solution based on <code>vh</code>, or <code>viewpoint height</code>, for details visit <a href="http://www.w3schools.com/cssref/css_units.asp" rel="noreferrer">CSS units</a>. It is based on this <a href="https://stackoverflow.com/a/29658808/4544095">solution</a>, which uses flex instead.</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>* {\r\n    /* personal preference */\r\n    margin: 0;\r\n    padding: 0;\r\n}\r\nhtml {\r\n    /* make sure we use up the whole viewport */\r\n    width: 100%;\r\n    min-height: 100vh;\r\n    /* for debugging, a red background lets us see any seams */\r\n    background-color: red;\r\n}\r\nbody {\r\n    /* make sure we use the full width but allow for more height */\r\n    width: 100%;\r\n    min-height: 100vh; /* this helps with the sticky footer */\r\n}\r\nmain {\r\n    /* for debugging, a blue background lets us see the content */\r\n    background-color: skyblue;\r\n min-height: calc(100vh - 2.5em); /* this leaves space for the sticky footer */\r\n}\r\nfooter {\r\n    /* for debugging, a gray background lets us see the footer */\r\n    background-color: gray;\r\n min-height:2.5em;\r\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;main&gt;\r\n    &lt;p&gt;This is the content. Resize the viewport vertically to see how the footer behaves.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n    &lt;p&gt;This is the content.&lt;/p&gt;\r\n&lt;/main&gt;\r\n&lt;footer&gt;\r\n    &lt;p&gt;This is the footer. Resize the viewport horizontally to see how the height behaves when text wraps.&lt;/p&gt;\r\n    &lt;p&gt;This is the footer.&lt;/p&gt;\r\n&lt;/footer&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<blockquote>\n  <p>The units are vw , vh, vmax, vmin. Basically, each unit is equal to 1% of viewport size. So, as the viewport changes, the browser computes that value and adjusts accordingly.</p>\n</blockquote>\n\n<p>You may find more information <a href="http://sosweetcreative.com/2738/viewport-sized-typography" rel="noreferrer">here:</a></p>\n\n<blockquote>\n  <p>Specifically:</p>\n\n<pre><code>1vw (viewport width) = 1% of viewport width\n1vh (viewport height) = 1% of viewport height\n1vmin (viewport minimum) = 1vw or 1vh, whatever is smallest\n1vmax (viewport minimum) = 1vw or 1vh, whatever is largest\n</code></pre>\n</blockquote>\n'}, {'answer_id': 66713668, 'author': 'peja', 'author_id': 3617261, 'author_profile': 'https://Stackoverflow.com/users/3617261', 'pm_score': 0, 'selected': False, 'text': '<p>As specified <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/height#formal_definition" rel="nofollow noreferrer">the height property in MDN docs</a> it is not inherited. So you need it to set to 100%. As it is known any web page starts with html then body as its child, you need to set <strong>height: 100%</strong> in both of them.</p>\n<pre><code>html,\n   body {\n     height: 100%;\n   }\n\n&lt;html&gt;\n  &lt;body&gt;\n\n  &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n<p>And any child marked with height 100% will be the portion of 100 of parent height. In the example style above, we set the html tag as a 100%, it will be full height of the available screen height. Then the body is 100%, and so it will also be the full height, since it\'s parent is html.</p>\n'}]
['https://Stackoverflow.com/questions/25238', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1725/']