How to add a Div with horizontal scrolling only with CSS?

Spread the love

Sometimes, we want to add a Div with horizontal scrolling only with CSS.

In this article, we’ll look at how to add a Div with horizontal scrolling only with CSS.

How to add a Div with horizontal scrolling only with CSS?

To add a Div with horizontal scrolling only with CSS, we enable horizontal overflow.

For instance, we write

.container {
  width: 30em;
  overflow-x: auto;
  white-space: nowrap;
}

to add overflow-x: auto; to let us enable horizontal scrolling.

We add white-space: nowrap; to stop content from wrapping when it overflows the row.

Conclusion

To add a Div with horizontal scrolling only with CSS, we enable horizontal overflow.

Leave a Reply

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