2013-03-08 109 views
0

如何防止td比表格最大寬度變寬?我無法設置像素大小,因爲它用於填充表格的其餘寬度。當我將最大寬度設置爲100%時,這似乎是其內容寬度。表內容隨內容擴展

<div class="content" style="width: 200px; max-width: 200px;"> 
    <table class="outer-table" style="width: 100%; max-width: 100%;"> 
     <tr> 
      <td style="white-space: nowrap; max-width: 100%; background-color: yellow;"> 
       <div class="inner-div" style="width: 100%; max-width: 100%; overflow: scroll;"> 
       This is a table width to much content. I use "white-space: nowrap" to force it to grow wide. 
       </div> 
      </td> 
     </tr> 
    </table> 
    </div> 

看到它在行動:http://jsfiddle.net/TxqT4/1/

回答

0

只是從你的TD風格

使用NOWRAP屬性,你迫使TD的內容留在線即除去white-space: nowrap。沒有斷行,這就是爲什麼它是創造問題

看到這裏Update code

+0

我使用NOWRAP故意的。但爲什麼「overflow:scroll」不生效?因爲它看起來好像td的100%寬度不是我所期望的表格寬度。 – einord 2013-03-08 08:03:20

+1

@einord我有你的問題。所以只需添加溢出:滾動或自動到父div。它會解決你的問題看看這裏http://jsfiddle.net/TxqT4/4/。請隨時回覆。 – Sachin 2013-03-08 09:57:35

+0

謝謝!這解決了我的問題。我爲什麼沒有想到它? – einord 2013-03-08 11:05:37