I've spent a few hours looking for an answer to this, but others' scenarios for which solutions have been provided seem to be slightly more straightforward than mine.
Is there a way to have a position:fixed element inside a fixed size div without the element spilling out of the div?
In other words, if the fixed element grows, I'd like scrollbars to appear in the div (horizontal and vertical), but I need the element to remain fixed when you scroll vertically (I'm planning on using JQuery to achieve this).
Thanks 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: The overall effect I'm looking for is like with the middle box here: http://demo.rickyh.co.uk/css-position-x-and-position-y/ except applied within a scrollable div instead of the whole viewport.