I'm writing a web app, predominantly in AngularJS using CSS's flexbox for some of the layout, if that matters. I've been going crazy over the last few hours trying to solve the problem I'm currently stuck on.
The problem I'm running into is as follows:
There are two side by side div
s on a page. The leftmost div
is a menu that must always be the height of the document's content or the browser window (whichever is greater). The rightmost div
is the one that content gets appended to dynamically. When the program starts, the rightmost div
is less than the height of the browser window (because it does not have much content) but as the application progresses, content gets added to it such that it eventually is much longer than the browser window.
A JSFiddle that shows the problem can be found by clicking here.
The HTML structure of the fiddle is mostly fixed (containers can be added but should not be removed) as this is a tremendous simplification of a complex application that has that same basic structure. Additionally, I set all the CSS heights to 100% solely because of reading another answer, not because I know they are required to make this work (I do want the menu to start out full screen even with minimal content, however).
The black div
represents the menu and the yellow div
represents the one that holds the content. When the "click me to add content" button is clicked, 100 lines of content are appended to the content div which then makes it longer than the window. The desired effect is for both the yellow and black div
s to expand such that the yellow div is as big as it needs to be to hold the content and the black div
is the same height as the yellow div
. Instead, what happens (as you can see) is neither the black nor the yellow div
s expand when the content is added and the content simply flows outside of the bounds of the yellow div
.
I've researched this problem to the best of my ability on stackoverflow and elsewhere and no presented solutions appear to work for this type of dynamic content (although I may be, and problably am, missing something). Such answers like this one and this one recommend using the min-height
property on some elements but when I tried it, the black and yellow div
s started small (size of the content, not the full browser height) but did expand correctly. Basically, when I try other people's solutions, it appears that I can either have div
s that start out small (less than full screen) and grow correctly or start out correctly (full screen, even though initial content is smaller) and don't grow but not both (I would like div
s that start out correctly and grow to fit content). Additionally, answers such as this one suggest combinations of min-height
and height
to achieve one effect or the other, but not the both I am looking for.
I would really appreciate any help I can get and I thank you for your time.
EDIT:
Truncated version, for those who are in a rush.
I'd like the ability to make two side by side div
s start out the full height of the browser window even when there is no content in them. Then, when enough content is added to one of the div
s to make it larger than the browser, both div
s expand to fit the available content. JSFiddle is available at this link. The problem with the fiddle is the yellow and black div
s don't expand to fit the new content when the add new content button is pushed.