Menu Close

How to make div fixed scrolling to that div with CSS?

Sometimes, we want to make div fixed scrolling to that div with CSS.

In this article, we’ll look at how to make div fixed scrolling to that div with CSS.

How to make div fixed scrolling to that div with CSS?

To make div fixed scrolling to that div with CSS, we can use the position: sticky CSS property.

For instance, we write

position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 1;

to set position to sticky and z-index to 1 to make the element with the sticky position show on top after we scroll to it.

Conclusion

To make div fixed scrolling to that div with CSS, we can use the position: sticky CSS property.

Posted in CSS