I've run into an issue while trying to make a side div sticky using Bootstrap 5. I applied the position-sticky
class, but it doesn't seem to work as expected. Surprisingly, it works for the top div that I also want to stick. Adding fixed-top
or sticky-top
to the side div causes its height to expand and fill the parent container, which is not the behavior I desire.
<!DOCTYPE html>
<html>
<head>
<title>
Title
</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a2afafb4b3b4b2a1b080f5eef2eef2">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<div class="layout-wrapper layout-content-navbar">
<div class="layout-container">
<div class="layout-page">
<div class="content-wrapper">
<div class="container-xxl flex-grow-1 container-p-y">
<div id="divMain">
<div class="row mb-3">
<div class="card card-action mb-4 col-md-12">
<div class="card-header align-items-center position-sticky fixed-top" style="background:white;">
<h5 class="card-action-title mb-0">Title</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3">
<div class="position-sticky">
<div style="border:1px solid black;min-height:500px;">
I WANT THIS DIV TO BE STICKY
</div>
</div>
</div>
<div class="col-md-9">
<h5>Data</h5>
<h5>Data</h5>
<h5>Data</h5>
<h5>Data</h5>
...
<h5>Data</h5>
<h5>Data</h5>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fbf6f6edeaedebf8e9d9acb7abb7ab">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk" crossorigin="anonymous"></script>
</body>
</html>