css - 空白 : nowrap vs white-space: normal why is the effect on floating elements so big?

标签 css alignment

Definition from w3c : 正常 空白序列将折叠成一个空白。文本将在必要时换行。这是默认播放它» nowrap 空白序列将折叠成一个空白。文本永远不会换行到下一行。文本在同一行继续,直到遇到
标记。

那么为什么 float 元素的外观会有如此大的不同呢?

例如比较一下:

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 我在火狐 10.0.4 white-space: nowrap results in 2 rows in firefox 10.0.4

最佳答案

我有点收回我上面最初的评论。如果您在 white-space: nowrap div 中有 divfloat 并且您的父级 div 有一个固定的宽度,你会得到我在评论中提到的内容。但是,如果您的 child 是 inlineinline-block,那么这些 child div 将继续超出右侧 overflow(就像内联文本所做的那样)。通常,当您 float: left 时,子级到达父级的末尾并换行到另一行。

看看这个 fiddle插图。

关于css - 空白 : nowrap vs white-space: normal why is the effect on floating elements so big?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12407541/

相关文章:

ios - UITextField 文本在动态类型调整大小后垂直移动

c++ - SSE、内在函数和对齐

jquery - 专注于页面而不是元素

html - IE 中 UL 内的 float 元素低于 float 输入 - 但在 Chrome 中没问题

css - 无法将 margin-top 设置为菜单 div

objective-c - Cocoa osx NSCombobox 对齐项目中心

alignment - Ada 中的 Alignment 子句有什么作用?

css - 添加一个 css 类以在 Rails 中选择

image - 为什么没有仔细显示 css 边框?

css - 加载 twitter bootstrap responsive.css 时如何防止特定元素的响应行为?