How to make the scrollbar on a div only visible when necessary with CSS?

Spread the love

Sometimes, we want to make the scrollbar on a div only visible when necessary with CSS.

In this article, we’ll look at how to make the scrollbar on a div only visible when necessary with CSS.

How to make the scrollbar on a div only visible when necessary with CSS?

To make the scrollbar on a div only visible when necessary with CSS, we set the overflow property.

For instance, we write

<div style="overflow: auto; width: 400px; height: 400px">here is some text</div>

to add the overflow: auto; style to make the scrollbars show when there’s overflowing content.

Conclusion

To make the scrollbar on a div only visible when necessary with CSS, we set the overflow property.

Leave a Reply

Your email address will not be published.