Ritu Singh
Problem:
My web page has 3 divs. I have made the second div sticky. My expectation was that when I scroll div1 would scroll off the top, div2 would stick when it reached the top, and then div3 would scroll over div2 and off the top leaving div2 still stuck in place. Instead what actually happens is that when div3 reaches the top it and div2 both scroll off the top together.
Can anyone suggest a way to accomplish what I want?
Regarding the example code: Use the checkbox to make div2's position be either sticky or relative like the others.
Solution:
The solution to your problem is setting height of the body to 100%. The reason for this is that the parent container of the sticky element must have a defined height. Even if the height of html is set to 500vh the parent element of your div is the body so the body has to have a defined height in order for div2 to be sticky.
Suggested blogs:
>Removing ASCII formatted characters from my CAN messages in Python
>Why `import` does not work in this case (in `exec`)?
>Fix my form calling the wrong Django view error
>How to load static files using Nginx, Docker, and Django?
>How to tell Django "if anything in urlpatterns does not match the GET string?
>How can I browser to render links in streamed content in Django?
>Access the "model" attribute for a ListView in Django for template
>How to use a function to print S3 data to HTML using Django?
>How to make a code executed after an entry is inserted, removed or updated?