2011-03-22 122 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