I want to be able to keep elements on the right side of a div within the same location (similar to position: fixed), however I want to keep the div within its parent. required format
I want the "Stays in view" element to not leave its parents div but stay within the viewport.
I’ve tried position: fixed however its very hard to keep it from overlapping other elements with multiple viewports and will leave its parents div.
Thanks Parth M for the help. With your suggested edits:
latest output
2
Answers
The position: sticky property on the .sticky element makes it stick to the top of its parent .sidebar when you scroll within the .container.
The top: 0; specifies that the element should stick to the top of the container. You can adjust this value to change where the element sticks within the viewport.
The position: relative; on the .sidebar ensures that the sticky element is constrained within the bounds of the .sidebar as you scroll.
Use position: sticky;