【发布时间】:2012-09-13 13:35:07
【问题描述】:
Definition from w3c:
正常 空白序列将折叠成一个空白。文本将在必要时换行。这是默认播放 »
nowrap 空白序列将折叠成一个空白。文本永远不会换行到下一行。文本在同一行继续,直到遇到
标记。
那么为什么浮动元素的外观会有这么大的不同呢?
例如比较一下:
JsBin with white-space normal showing a nicely aligned layout
<table>
<thead>
<tr>
<th>
<div style="background-color: lightblue; width: 600px; white-space: normal;">
<span style="display: inline-block; height:20px; background-color: red; margin: 5px 3px;float: left;">
Button
</span>
<span style="display: inline-block; height:20px; background-color: red; margin: 5px 3px;float: none;">
Button
</span>
<span style="display: inline-block; height:20px; background-color: red; margin: 5px 3px; float:right;">
Button right
</span>
<div style="clear: both" />
</div>
</th>
</tr>
</thead>
<tbody>
<tr><td>note: white-space is normal here</td></tr>
</tbody>
</table>
White this where white-space: nowrap is used
和上面的代码一样,只是这次 white-space: nowrap;
有人知道了吗? [编辑] 正如人们评论的那样,他们看不出有什么区别,我上传了有问题的空白的屏幕截图:nowrap 我在 Firefox 10.0.4
【问题讨论】:
-
你为什么要做
white-space: nowrap;?没有它也可以工作:little link. -
我实际上没有看到任何区别。此外,您没有任何可以首先换行的文本。除非您的文本通常会换行到另一行,否则您不会看到差异。
-
white-space: nowrap对于使用text-overflow: ellipse也很重要 -
@Scrimothy
text-overflow: ellipse;在带有浮动divs 的元素上?我不明白这一点。 -
@Abody97,在这种情况下你不需要它。我只是把它扔进去了,因为总体问题是关于
white-space:nowrap和white-space:normal之间的差异。