2011-03-22 121 views
3

在IE8中工作正常。在Firefox中,如果我從td中刪除nowrap屬性,文本會被正確包裝,但是不會刪除nowrap文本而不會被包裝。如何覆蓋表格nowrap屬性

有沒有什麼辦法在firefox中通過css覆蓋nowrap屬性。

<div style="width:100%;border:1px solid #eaeaea"> 
<table style="width:100%;word-wrap:break-word;table-layout:fixed" border="1" > 
    <tr> 
     <td> 
      thisssssssssssssssssssssssssss 
     </td> 
     <td nowrap="" style="word-wrap:break-word;"> 
      22222222thisssssssssssssssssssssssssss22222222thisssssssssssssssssssssssssss22222222thisssssssssssssssssssssssssss 
     </td> 
    </tr> 
</table> 
</div> 
+0

nowrap =「nowrap」將其關閉(已棄用 - btw)。不使用它將允許你爲''td style = ...'打包。 – Dawson 2011-03-22 07:32:30

回答

0

一個快速的想法......在你看覆蓋FF之前。查看Chrome/Safari等正在做什麼,並考慮用IE 8條件(多數規則方法)覆蓋該CSS。

<!--[if IF 8]>...

0

我不知道如果我完全理解你的處境,但這樣的事情可能工作好一點:

<style type="text/css"> 
    #myDiv { width:100%; border:1px solid #eaeaea; } 

    #myTable { width:100%; word-wrap:break-word; table-layout:fixed } 
    #myTable th, #myTable td { border:1px solid #000000; } 

    td.breakWord { word-wrap:break-word; white-space:nowrap; } 
</style> 


<!--[if IE]> 
<style type="text/css"> 
    td.breakWord { white-space:normal; } 
</style> 
<![endif]--> 


<div id="myDiv"> 
<table id="myTable" > 
    <tr> 
     <td> 
      thisssssssssssssssssssssssssss 
     </td> 
     <td class="breakWord"> 
      2222222thisssssssssssssssssssssssssss22222222thisssssssssssssssssssssssssss22222222thisssssssssssssssssssssssssss 
     </td> 
    </tr> 
</table> 
</div> 

您可以在http://www.quirksmode.org/css/condcom.html

閱讀更多有關條件註釋
13
table { 
    table-layout:fixed; 
    width:100%; 
    word-wrap:break-word; 
} 

td { 
white-space: normal; 
} 

白色空間規則覆蓋無包裝屬性(您的問題),單詞換行規則打破牢不可破的字符串

+1

有關空白覆蓋nowrap的信息對我非常有用,非常感謝! – 2013-07-21 13:38:32

+0

還發現空白覆蓋非常有用。謝謝@clairesuzy – 2014-03-02 22:59:28