2012-09-13 29 views
3

Definition from w3c正常空格的序列將崩潰爲單個空白。文字將在必要時包裝。這是默認播放» nowrap空格的序列將摺疊成單個空格。文本將永遠不會換行到下一行。文本繼續在同一行,直到遇到
標記。White-space:nowrap vs white-space:normal爲什麼對浮動元素的影響如此之大?

那麼爲什麼它在浮動元素的外觀上有如此多的不同呢?

例如比較這:

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

這是相同的代碼上面,只是這一次的空白:NOWRAP;

有人有線索? [編輯] 人們評論說,他們看不出有什麼區別,我上傳的問題空白的屏幕截圖:NOWRAP 我在Firefox 10.0.4 white-space: nowrap results in 2 rows in firefox 10.0.4

+1

爲什麼你要做'白空間:nowrap;'首先呢?它沒有它:[小鏈接](http://jsbin.com/ibifoq/28/edit)。 – Chris

+1

我其實沒有看到任何區別。另外,您沒有任何文字可以放在首位。除非您的文本通常會換行到另一行,否則您不應該看到區別。 – Scrimothy

+0

'white-space:nowrap'對於使用'text-overflow:ellipse'也是至關重要的# – Scrimothy

回答

4

我有點收回上述我的初步意見。如果你在white-space: nowrap div裏有div s float,並且你的父母div有固定的寬度,你會得到我在我的評論中提到的。但是,如果您的孩子是inlineinline-block那麼那些孩子divs只會繼續超越右邊overflow(就像內聯文本會做什麼)。通常,當你float: left孩子到達父母的盡頭,幷包裝到另一行。

看看這個fiddle插圖。

+0

我接受這個答案,因爲它是一個非常好的小提琴,它似乎我的問題是非常特定於瀏覽器。 – Toskan

2

我想補充說明http://jsfiddle.net/cstephe/tNHLL/顯示了在Firefox 10中,order是如何影響這個的,至少我會在更新版本中回家時檢查這個。

編輯:這是它如何看起來對我本地。

enter image description here

<h2>float first: nowrap/Children: floating blocks</h2> 
<div class="wrapper nowrap"> 
    <div class="inlineBlock floating"></div> 
    <div class="inlineBlock floating float-right">r</div> 
    <div class="inlineBlock">something</div> 

</div> 
<div class="clearfix"></div> 
<h2>typical order: nowrap/Children: floating blocks</h2> 
<div class="wrapper nowrap"> 
    <div class="inlineBlock floating"></div> 

    <div class="inlineBlock">something</div> 
    <div class="inlineBlock floating float-right">r</div> 
</div> 
+0

似乎看起來在鉻22和火狐10相同。 – Toskan

+0

我會在我的家用電腦上測試它,但到目前爲止,我已經看到了ff10和移動safari的區別 –

+0

它看起來就像我在鉻版本22.0 .1229.94米和ff 10.0.9:你看起來有什麼不同?你究竟是什麼意思? – Toskan

相關問題