CSS Position Fixed Issue
Hi, my button for some reason won't stay fixed to the div its inside, even though I have "position: relative;" on my content div. Why is this happening?
2 Replies
position: fixed
doesn't care about the parent, it gets hoisted out of the stack and placed at the position relative to the page itself rather than the parent. you should use position: absolute
or position: sticky
instead. docs:
Fixed vs Sticky: https://www.kevinpowell.co/article/positition-fixed-vs-sticky/
Positioning docs: https://www.w3schools.com/css/css_positioning.aspPosition fixed vs position sticky | Position fixed vs position sticky
A look at the similarities and differences between CSS's position fixed and sticky, as well as when you might use one over the other
thank you ❤️
I was not aware that of these differences