Let's say I have a div that has overflow:auto
and a scrollbar as a result. I would like to add a div that takes up the entire parent div as you scroll down, not just the height of the parent div as it's rendered on the screen.
If my description is a little unclear, look at the code and jsfiddle below. I would like the red column to extend all the way to the bottom of the parent when you scroll the parent down. You shouldn't be able to see the bottom of the red box.
How can I go about doing this?
.parent {
overflow: auto;
overflow-x: hidden;
position: relative;
height: 300px;
width: 200px;
border: 1px solid black;
}
.line {
border-bottom: 1.5px solid black;
height: 50px;
margin-left: 7px;
margin-right: 7px;
position: relative;
}
.box {
position: absolute;
top: 0;
height: 100%;
background-color: red;
width: 50%;
left: 20%;
z-index: 10;
}
<div class="parent">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="box"></div>
</div>