I have the following HTML: http://jsfiddle.net/fMs67/. I'd like to make the div2 to respect the size of div1 and scroll the contents of div3.
Is this possible?
Thanks!
UPDATE-1:
This is the more advanced case that I oversimplified when I asked the question: http://jsfiddle.net/Wcgvt/. I need somehow that header+it's sibling div to not overflow the parent div's size.
Adding position: relative
to the parent, and a max-height:100%
; on div2 works.
<body> <div id="div1" style="height: 500px;position:relative;"> <div id="div2" style="max-height:100%;overflow:auto;border:1px solid red;"> <div id="div3" style="height:1500px;border:5px solid yellow;">hello</div> </div> </div> </body>
Update: The following shows the "updated" example and answer. http://jsfiddle.net/Wcgvt/181/
The secret there is to use box-sizing: border-box
, and some padding to make the second div height 100%, but move it's content down 50px. Then wrap the content in a div with overflow: auto
to contain the scrollbar. Pay attention to z-indexes to keep all the text selectable - hope this helps, several years later.
If you put overflow: scroll
on a fixed height div
, the div
will scroll if the contents take up too much space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With