Show Output
<!DOCTYPE htpl> <htpl lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 5 Position Classes</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script> <style> .bs-example{ margin: 20px; padding: 20px; height: 200px; overflow-y: auto; border: 1px solid #ccc; } .box{ padding: 20px; background: #abb1b8; top: 0; } </style> </head> <body> <div class="bs-example"> <p class="mb-3"><strong>Note:</strong> The element is positioned similarly to a relatively positioned box and it "sticks" to its nearest ancestor that has a "scrolling mechanism". Also, you must also specify at least one of left, right, top, or bottom property for sticky positioning to work. Scroll the area to see how it works.</p> <div class="box position-sticky">.position-sticky</div> <p class="mt-3">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu sem tempor, varius quam at, luctus dui. Mauris magna metus, dapibus nec turpis vel, semper malesuada ante. Vestibulum id metus ac nisl bibendum scelerisque non non purus. Suspendisse varius nibh non aliquet sagittis. In tincidunt orci sit amet elementum vestibulum. Vivamus fermentum in arcu in aliquam. Quisque aliquam porta odio in fringilla. Vivamus nisl leo, blandit at bibendum eu, tristique eget risus. Integer aliquet quam ut elit suscipit, id interdum neque porttitor. Integer faucibus ligula.</p> </div> </body>