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.