How can I position content in a container with some minimum distance to the bottom? Specifically, I want the blue element to stop before reaching the very bottom of the container.
I could stack two containers on top of each other and only include the sticky content in the first one. However, since the container may expand with user interaction, this approach is not feasible as I need the sticky content to scroll further over the 'new' content.
In essence, I require the sticky content to maintain a minimum distance from the bottom of the container at all times. Is there an elegant way to achieve this?
Initially, I thought adding the bottom
attribute to the element might work, but it did not have the desired effect. I also experimented with a JavaScript solution that involved switching between sticky
and absolute
positioning based on the user's scroll position, but this proved ineffective.
Any assistance or guidance on this matter would be greatly appreciated.
body{
min-height:2000px;
}
.content{
width:300px;
background:red;
margin-top:20px;
}
.overlayContent{
width:100%;
min-height:100px;
padding:10px;
background:blue;
position:sticky;
top:0;
bottom:20px;
z-index:999;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="02606d6d76717670637242372c322c33">[email protected]</a>/dist/css/bootstrap.min.css" integrity="undefined" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5d7dadac1c6c1c7d4c5f5809b859b84">[email protected]</a>/dist/js/bootstrap.min.js" integrity="undefined" crossorigin="anonymous"></script>
<body>
<div class="content">
<div class="overlayContent">
</div>
<p class="mt-16">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ante enim, maximus vitae rutrum eu, ultrices ac mauris. In ac libero nisi. Suspendisse vel dictum purus. Etiam in orci orci. Donec tincidunt turpis a justo consequat, eu sodales lorem ultrices. Suspendisse dictum massa vitae elementum fringilla. Fusce est sapien, faucibus ut ultricies eget, ultrices sed turpis. Praesent ac lectus eget eros fringilla aliquam.
<a class="btn btn-primary w-100" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Expand
</a>
...
</body>