Sometimes, we want to force div contents to stay in one line with HTML and CSS.
In this article, we’ll look at how to force div contents to stay in one line with HTML and CSS.
How to force div contents to stay in one line with HTML and CSS?
To force div contents to stay in one line with HTML and CSS, we use the overflow
and white-space
CSS properties.
For instance, we write
div {
border: 1px solid black;
width: 70px;
overflow: hidden;
white-space: nowrap;
}
to hide the div’s overflowing content with overflow: hidden;
and we make the content stay in 1 row with white-space: nowrap;
.
Conclusion
To force div contents to stay in one line with HTML and CSS, we use the overflow
and white-space
CSS properties.