html - scroll div with uncertain height -


i have situation have want scroll main content div not header. header has fixed height, , content div meant stretch rest of vertical space, scroll bar if content stretches beyond bottom of page. use absolute positioning on content div (top:height-of-header, bottom:0, left:0, right:0), , set overflow-x auto. however, it's complicated fact have additional div between header , content has flexible height based on contents , appears (i have button toggles visibility of div). such, can't use absolute positioning content div because top distance varies. can't use percentage heights because want non scrolling portions just-right height content, rather based on percentage of page.

here's simplified version of setup:

<div id="header"></div>     <--- fixed height <div id="adddiv"></div>     <--- not visible. flexible height. <div id="content"></div>    <--- 1 want scrolling 

edit: added jsfiddle larger example here: https://jsfiddle.net/r7b30v2f/4/ (without scrollbar working way want)

since i'm using javascript handle toggling of "middle" div, use javascript change top value content div depending on whether or not middle div displaying. prefer css solution if there one.

it place scroll bar in contents div if contents div height or max-height set. css example:

#contents {     max-height: 250px;     width: 100%;     overflow-y: auto; } 

edit: try setting height figuring out height of header + height of adddiv.

var headerheight = document.getelementbyid("header").offsetheight; var adddivheight = document.getelementbyid("adddiv").offsetheight; var heightused = headerheight + adddivheight; var totalheight = screen.height; var height = totalheight - heightused; 

(i did try couldn't work, thought i'd share think solution.)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -