Currently, I am facing an issue where I need to scroll the main content div while keeping the header fixed. The header has a set height, and the content div should fill the remaining vertical space with a scroll bar when needed. Normally, I would use absolute positioning on the content div (
top:height-of-header, bottom:0, left:0, right:0
) and set overflow-x
to auto
. However, the complexity arises from having an additional div between the header and content, which has a dynamic height based on its contents and may or may not be visible. Due to this setup, it is challenging to use absolute positioning for the content div as the top distance varies. Using percentage heights is also not ideal as I want the non-scrolling portions to adjust their height based on their content rather than a percentage of the page.
Here is a simplified version of the structure:
<div id="header"></div> <--- Fixed height
<div id="adddiv"></div> <--- Not always visible. Flexible height.
<div id="content"></div> <--- Only intended for scrolling
Edit: A larger example can be found in this jsfiddle link: https://jsfiddle.net/r7b30v2f/4/ (The scrollbar behavior is not as desired)
As I am using JavaScript to handle the toggling of the "middle" div, I could dynamically change the top value for the content div based on the visibility of the middle div. However, I am exploring a CSS solution first if one exists.