2012-12-05 54 views
2

我有以下的基本結構:CSS空白級聯不正確?

<table> 
    <tr> 
    <td> 
     <div id="root"> 
     <div>Lots of text here</div> 
     <div>Lots more test here</div> 
     </div> 
    </td> 
    <td>I should always be visible</td> 
    </tr> 
</table> 

而這個CSS:

#root { 
    white-space: nowrap; 
    overflow: hidden; 
} 
#root>div { 
    white-space: normal; 
    display: inline-block; 
    width: 100%; 
} 

的想法是,每個孩子<div> S的「頁」,可以通過水平滾動顯示。儘管normal會影響他們(並且根據檢查員的說法,他們正在影響他們),儘管這些元素確實並排出現,但其中的文字似乎仍受nowrap的影響。我已經在IE9(white-space工作正常),和Chrome 23(white-space仍然nowrap)測試。

有沒有解決方法,或者是Chrome中的(嚴重)錯誤?

+0

它看起來是一樣的,以我在IE9(瀏覽器模式:IE9,文檔模式IE9)和鉻23 http://jsfiddle.net/mowglisanu/RgbY4/ – Musa

回答

1

它看起來像在this fiddle here罰款。

我撥弄包含一些Lorem存有你的例子hucked在那裏填寫:

HTML:

<div id="root"> 
    <div>Lots of text here</div> 
    <div>Even more text here... well, in the fiddle it's the exact same text...</div> 
</div> 

CSS:

#root { 
    white-space: nowrap; 
} 

#root > div { 
    white-space: normal; 
    display: inline-block; 
    width: 100%; 
} 

正如你可以看到的截圖下面,將空格正確設置爲normal

screenshot!

+0

我終於想通了什麼區別在於我的頁面和你的小提琴:'root'元素實際上在一個表格單元格內。嘗試在'root'元素周圍加入'

​​'和'
',你就會看到我遇到的問題。通過在表中添加'table-layout:fixed; width:100%'來解決問題,但問題在於實際表中不只有一個單元格,而且它們的寬度不一定是已知的(我不想對它們進行硬編碼)。 [此更新的小提琴](http://jsfiddle.net/VTKGC/4/)更好地顯示了發生了什麼 –

+1

通過刪除表格解決了問題。現在浮動工作正常,即使它不是以前。答案接受爲最佳答案(或在這種情況下「唯一答案」:D) –

+0

@Kolink我也遇到了這個問題(Chrome v29),這是沒有表我用ul> li爲內嵌塊佈局。仍試圖找出解決方法... – hitautodestruct