2013-09-21 56 views
0
<table style="table-layout:fixed;">  
    <tr> 
     <td width="221" style="overflow:hidden"> 
      //A very long text that meant to overflow 
     </td> 
    </tr> 
</table> 

經過一番研究,上述代碼應該可以正常工作,但事實並非如此。只有在td中有一個額外的div標籤,其樣式overflow:hidden才能實現。HTML溢出不適用於TD和溢出概念的TR

而另一個問題是如何實現溢出到高度?如果可以提供任何示例代碼,將不勝感激。

回答

0

爲了控制HIGHT只有 u必須使用CSS屬性overflow-y代替overflow。要應用滾動,你必須使用overflow-y: scroll和其他類似的overflow

0

Working Demo Here

可以模擬溢出:隱藏不alterate表格的佈局,只是在TD裏面把兩個div:

<div style="position: relative;"> 
    <div style="overflow: hidden; width: 320px; height: 150px;"> 

    content 

    </div> 
</div> 

查看JSFiddle

+0

你不需要添加絕對位置 – eapo

+0

更新建議由eaposztrof – ReDEyeS

1

侑代碼應指定更多的細節到你的對象,就像空白一樣,因爲ling文本自動包裝在td中。

<table style="table-layout:fixed;">  
<tr> 
    <td width="221" style="overflow:hidden;display:block;width:5em;white-space:nowrap;background-color:#ccc;"> 
     //A very long text that meant to overflow 
    </td> 
</tr> 
0

,如果你想爲特定的寬度和高度溢出,你應該CSS屬性display:block添加到<td>和其他人說之前寬度溢出,你應該設置white-space:nowrap它阻止你的文字是包裝,this是一個working exampleoverflow:scroll爲更好的underestanging