2011-03-20 99 views
3

我不知道這一點......幫助空白:NOWRAP正常,在IE

我有一個DIV叫「#ContentContainer」,它的寬度是100%,它需要的空白nowrap,所以它的內部擴展和崩潰將冒險超出窗口,並創建一個水平滾動。在擴展和收縮的div中,我有文本和圖像。在IE中,這些內部div有白色空間:nowrap應用於他們...我已經設置了白色空間爲正常,但IE不承認..任何人都可以幫忙嗎?

這裏CSS:

#ContentContainer { 
    position: relative; 
    height: 480px; 
    width: 100%; 
    margin: 10px 0px 0px 0px; 
    border: 1px solid blue; 
    white-space: nowrap; 
} 

.column { 
    position: relative; 
    white-space: normal; 
    width: 220px; 
    top: 0px; 
    border-left: 1px solid #999; 
    border-right: 1px solid #999; 
    height: 420px; 
    margin: 20px 30px 0px 0px; 
    *display: inline; 
    vertical-align: top; 
} 

和我的HTML:

<div id="#ContentContainer"> 
    <div class="column"> 
     Text that needs to have a white-space or normal. It needs to wrap. Text that needs to have a white-space or normal. It needs to wrap. Text that needs to have a white-space or normal. It needs to wrap. 
    </div> 

    <div class="column"> 
     Text that needs to have a white-space or normal. It needs to wrap. Text that needs to have a white-space or normal. It needs to wrap. Text that needs to have a white-space or normal. It needs to wrap. 
    </div> 

    <div class="column"> 
     Text that needs to have a white-space or normal. It needs to wrap. Text that needs to have a white-space or normal. It needs to wrap. Text that needs to have a white-space or normal. It needs to wrap. 
    </div> 

</div> 

有人嗎?

+0

的東西我有同樣的問題,並沒有找到任何解決方案。不幸的是,很多人誤解了這個問題:它不是白色空間:nowrap;不起作用,但是它曾經爲所有後代設置_keeps_on_,似乎無法取消它(至少在IE8中)。 – 2013-06-28 17:16:15

回答

3

所有版本的IE都支持white-space:nowrap屬性,所以這應該對你很好。

您的問題不是您的CSS,而是您的HTML中的錯誤:您有<div id="#ContentContainer">,但這是不正確的:HTML代碼中的ID不應包含哈希符號(#)。它在CSS代碼中需要參考一個ID,但ID本身不應該包含它。

所以你的CSS是正確的,因爲它是:

#ContentContainer { 
    .... 
} 

,但你的HTML應該是這樣的:

<div id="ContentContainer"> 
    .... 

希望幫助。近三個星期後

1

之謎終於解開了:簡直可以解析和級聯CSS指令white-space:normal;正確的,但不能真正做任何事的(從而有效地使白色空間:NOWRAP;仙人)是一個錯誤的IE 5.5 。進入某種「兼容模式」或「怪癖模式」的IE的後續版本可能會重複這種不當行爲。它的出現受到IE的確切版本和DOCTYPE的內容(甚至是內部網與互聯網)的影響(這解釋了爲什麼它對許多人來說根本沒有出現,以及爲什麼這麼多答案似乎並沒有很有意義)。

擺脫這種不良行爲的確保方法是強制IE瀏覽器的所有版本使用較新的渲染模型(下面的例子使用「最新的渲染模式,每個版本能夠」),這需要向他們發送X-UA-Compatible HTTP標頭,如果可能的話從Web服務器中或者在每個相關文檔中作爲回退標頭。對於Apache服務器,添加到.htaccess中的命令類似於

Header set X-UA-Compatible "IE=edge,chrome=1" 

對於PHP它應該簡單地添加幾行代碼的東西,對於IIS它應該僅僅是一個配置的補充。 (您也可以嘗試僅使用HTML文件發送此標頭和/或僅將其發送到IE瀏覽器的優化。)

如果不能更改服務器的行爲,回退是每個相關文件的<頭> 之前添加所有 Javascript或CSS類似

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">