Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep DIV stretched to the bottom of the webpage with height 100% and overflow:auto using CSS only?
    primarykey
    data
    text
    <p>Salam all,</p> <p>I have an HTML page with two sections, header and content, the header height is known and fixed, and the content height should fullfill the rest area of the webpage. While the content section fills the rest area of the webpage it should show a scrollbar if the contents are greater than the height of the webpage ( I don't want to see a webpage scrollbar, only content DIV scrollbar).</p> <p>I have done this already (I've got the results that I want) using Javascript,</p> <p>My question is : can I make the same behaviour using CSS?</p> <p>Here is the code:</p> <p>CSS file (site.css):</p> <pre><code>html, body { height:100%; width:100%; padding:0; margin:0; } #header { height:85px; width:100%; background-color : yellow; } #container { height: 100%; width:auto; background-color : green; padding:2px; margin: 0 auto; } #maindiv { height:100%; width:100%; overflow:auto; } </code></pre> <p>Html file:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;link href="Site.css")" rel="stylesheet" type="text/css"/&gt; &lt;/head&gt; &lt;body onresize="onheightchanged()" onload="onheightchanged()"&gt; &lt;table id="header"&gt; &lt;tr&gt; &lt;td&gt; some headers &lt;br /&gt; some headers &lt;br /&gt; some headers &lt;br /&gt; some headers &lt;br /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div id="container"&gt; &lt;div id="maindiv"&gt; contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt; contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt; contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt; contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt; contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt; contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt;contents &lt;br /&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; function getDocHeight() { var D = document; return Math.max( Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight)); } function onheightchanged() { var container = document.getElementById("container"); var newheight = getDocHeight() - 90; // 90 = header height (85) + padding/margin (5) container.style.height = newheight + "px"; } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload