在CSS中,如何使文本不在第二行?

时间:2020-12-29 19:25:30

Suppose I have text inside a div right now. When I resize my browser to make it really small, the text goes on a 2nd line instead of making the scroll bar.

假设我现在在div中有文本。当我调整浏览器大小以使其非常小时,文本将在第2行而不是滚动条。

Instead, I would like to keep the text all on one line and just have a horizontal scroll bar. How can I do this? WIth overflow?

相反,我想将文本全部放在一行,只有一个水平滚动条。我怎样才能做到这一点?溢出?

2 个解决方案

#1


5  

Use white-space:

#myDiv { white-space: nowrap; }

Or:

<div style="white-space: nowrap;">Long text that I do not want wrapped</div>

#2


3  

You can turn off automatic wrapping using the white-space property, like this:

您可以使用white-space属性关闭自动换行,如下所示:

#theDiv { white-space: nowrap }

#1


5  

Use white-space:

#myDiv { white-space: nowrap; }

Or:

<div style="white-space: nowrap;">Long text that I do not want wrapped</div>

#2


3  

You can turn off automatic wrapping using the white-space property, like this:

您可以使用white-space属性关闭自动换行,如下所示:

#theDiv { white-space: nowrap }