Categories
CSS

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *