1

I have the following code. I want the second div to take the remaining space of the page and allow inner content to scroll if it overflows. But it does not seem to work.

<div style="max-height: 100vh; height: 100vh">
    <div style="height: 100%; display: flex; flex-direction: column">
       <div style="flex: 0 1 auto">
          This is some fixed heighted content
       </div>
       <div style="flex: 1 1 0%; overflow: auto">
          A lot of text content here that overflows the remaining space.
          So this div should take up the remaining available space (100vh - space of div above) 
          and the inner content should become scrollable
          But it ends up expanding the div to the text content and thus the whole screen becomes 
          scrollable instead of just the div
       </div>
    </div>
</div>

Any help would be much appreciated :)

Ujjwal Chadha
  • 133
  • 2
  • 8

3 Answers3

1

You did not close properly your div <div/> instead </div>, Also, less CSS can be used

body{margin:0}
<div style="height: 100vh; display: flex; flex-direction: column;">
   <div>
      This is some fixed heighted content
   </div>
   <div style="flex:1;overflow:auto;">
      A lot of text content here that overflows the remaining space.
      So this div should take up the remaining available space (100vh - space of div above) 
      and the inner content should become scrollable
      But it ends up expanding the div to the text content and thus the whole screen becomes 
      scrollable instead of just the divA lot of text content here that overflows the remaining space.
      So this div should take up the remaining available space (100vh - space of div above) 
      and the inner content should become scrollable
      But it ends up expanding the div to the text content and thus the whole screen becomes 
      scrollable instead of just the divA lot of text content here that overflows the remaining space.
      So this div should take up the remaining available space (100vh - space of div above) 
      and the inner content should become scrollable
      But it ends up expanding the div to the text content and thus the whole screen becomes 
      scrollable instead of just the divA lot of text content here that overflows the remaining space.
      So this div should take up the remaining available space (100vh - space of div above) 
      and the inner content should become scrollable
      But it ends up expanding the div to the text content and thus the whole screen becomes 
      scrollable instead of just the divA lot of text content here that overflows the remaining space.
      So this div should take up the remaining available space (100vh - space of div above) 
      and the inner content should become scrollable
      But it ends up expanding the div to the text content and thus the whole screen becomes 
      scrollable instead of just the divA lot of text content here that overflows the remaining space.
      So this div should take up the remaining available space (100vh - space of div above) 
      and the inner content should become scrollable
      But it ends up expanding the div to the text content and thus the whole screen becomes 
      scrollable instead of just the div
   </div>
</div>
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
0

enter image description here

a "max-height" css property might be needed here

JohnPion
  • 45
  • 1
-1

Your mistake in the code was when you did not close the div tag at the end.

fatemeh kazemi
  • 516
  • 6
  • 10