Html 将一串文本放在一行上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18753828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:18:53  来源:igfitidea点击:

Keeping a string of text together on one line

htmlcss

提问by user2574794

Is there a way to keep a string of text on one line, so that if the div width gets to small, the whole string will drop to the next line instead of half of it?

有没有办法将一串文本保留在一行上,这样如果 div 宽度变小,整个字符串将下降到下一行而不是一半?

Example:

例子:

"Industry Updates - 8th
 September 2013" 

often this happens on mobile browers whereas with to smaller width, the ideal situation is that the whole date stays together giving:

这种情况经常发生在移动浏览器上,而对于较小的宽度,理想的情况是整个日期保持在一起给出:

"Industry Updates - 
 8th September 2013" 

So is there a tag to use or a css trick to achieve this? Thanks

那么是否有一个标签可以使用或一个 css 技巧来实现这一点?谢谢

回答by JSous

CSS

CSS

.nowrap {
    white-space: nowrap;
}

HTML

HTML

<span class="nowrap">Industry Updates -</span>
<span class="nowrap">8th September 2013</span>

Any element with white-space: nowrapstays on one line

任何元素都white-space: nowrap停留在一行

回答by thgaskell

You want to use a non-breaking space in your HTML markup &nbsp;instead of a normal space.

您想在 HTML 标记中使用不间断空格&nbsp;而不是普通空格。

HTML

HTML

"Industry Updates - 8th&nbsp;September&nbsp;2013"