37

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

例子:

"Industry Updates - 8th
 September 2013" 

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

"Industry Updates - 
 8th September 2013" 

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

4

2 回答 2

77

CSS

.nowrap {
    white-space: nowrap;
}

HTML

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

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

于 2013-09-12T01:27:04.670 回答
53

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

HTML

"Industry Updates - 8th&nbsp;September&nbsp;2013" 
于 2013-09-12T01:20:09.213 回答