I have a 2 column grid, and I am trying to make the 2nd column sticky.
For some reason, it isn’t sticking. I googled the issue, and even used GPT4 and still couldn’t find the cause for the problem…
This is my react code:
.ftBlogRow-div{
display: grid;
grid-template-columns: 3fr 1.8fr;
}
.adBox-sticky{
align-self: start;
position: sticky;
top:0;
width: 100px;
height: 100px;
background-color: #1b1b1b;
color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.5.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.5.0/umd/react-dom.production.min.js"></script>
<div className="ftBlogRow-div">
<FtBlogRowBox limit={10} /> <div className="adBox-sticky"><p>testing</p></div>
</div>
2
Answers
I had to remove overflow-x: hidden from my global css...
That’s not how sticky will work.
position: sticky;
will not move an element out of the flow. means it will leave with its parent. To use sticky in a grid, you need a sticky element within a grid card element: