I tried to make my sidebar sticked at the top when everytime I scrolled but I dunno why it won’t stick at the top.
Here’s what I did and I expect it to sticked at the top when scrolled.
See my code below:
<section id="blog" class="blog">
<div class="container">
<div class="row">
<div class="col-lg-8">...</div>
<div class="col-lg-4">
<div class="sidebar">
I'm trying to stick this column at the top when scrolled.
</div>
</div>
</div>
</div>
</section>
CSS:
.blog .sidebar {
position: sticky;
top: 0;
right: 0;
overflow-y: auto;
}
3
Answers
The
<section>
needs to besticky
as well.It really depends on what that
row
class is doing. For example if it’s a flex container that displays its child elements in a row like the example below then your sticky rule will work (with a minor adjustment).your problem is you don’t have a parent element with position: relative. so to solve your problem you need to set:
and sidebar:
hope it will help you. Let me know the result