Is there a way to make the div .box
fixed within an absolute position div? My code doesn't seem to work, any suggestions on how to achieve this?
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80%;
height: 90%;
border: 1px solid black;
overflow-y: auto;
}
.box {
position: fixed;
height: 50px;
width: 90%;
top: 0;
left: 50%;
transform: translate(-50%);
border: 1px solid black;
}
<div class="container" align="center">
<div class="box">This div in fixed position does not stay fixed</div>
<div style="margin-top: 55px">Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
<div>Text</div>
</div>