Position absolute with overflown parent
Hi, I have an element that is positioned top right of the parent absolutely
<div className="absolute right-2 top-2">X</div>
The parent has overflow-y scrollbars, and when I scroll, the absolute child scrolls with the content, instead of being fixed there, but I cannot use position fixed because it's bound to the viewport, position sticky doesnt work either3 Replies
Can you share a codepen or a reproducible example?
Usually the issue is that the parent doesn't have
position: relative;
on it, but like croganm said, without seeing the code we can only guess. So codepen please!@π―πΌπ·πΌ.
I have experienced that issue when trying to replicate the arrow buttons for the horizontal scroll in the image below.
The trick usually is to have a parent element within which you put the scrollable and the buttons as siblings.
So, your absolute element isn't going to be positioned against the scrollable element, but on the parent which has a fixed width.