I've been searching for a solution to this issue for hours, but it seems that others' problems were simpler than mine.
Is there a way to keep a position:fixed element inside a fixed-sized div without it overflowing?
In simpler terms, I want scrollbars to appear in the div if the fixed element grows, while keeping the element fixed when scrolling vertically (I plan to use JQuery for this).
Thank you in advance.
<style>
.container {
width:200px;
height:200px;
border:solid 1px black;
overflow:scroll;
}
.fixed-element {
position: fixed;
width:250px;
height:100px;
background-color:red;
top:10px;
}
p {
min-width: 300px;
}
</style>
<body>
<div class="container">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<div class="fixed-element">
</div>
</div>
</body>
EDIT: I'm aiming for a similar effect as the middle box on this page: , but within a scrollable div instead of the entire viewport.