2014-06-13 39 views
2

我在span元素內有一長文本,我想用ellipsis截斷它。 span元素位於表格單元格內的div元素內。管理表格單元格內的div跨度的文本溢出

如何在單元格大小處截斷長文本。

這裏的HTML代碼片段:

<table> 
<tr> 
    <td> 
    <div> 
     <span> 
     this is a long sentence to test the text overflow 
     </span> 
    </div> 
    </td> 
</tr> 

而且CSS代碼:

table { 
width: 50px; 
table-layout: fixed; 
} 

td { 
border: 1px solid red; 
} 

span { 
white-space: nowrap; 
text-overflow: ellipsis; 
} 

這裏我的情況的jsfiddle: http://jsfiddle.net/Fedy2/wG3CF/

回答

6

測試這個例子我的朋友!

span { 
    white-space: nowrap; 
    text-overflow: ellipsis; 
    overflow:hidden; 
    width:100%; 
    display:block; 
} 

這裏更新的jsfiddle片段: http://jsfiddle.net/Fedy2/wG3CF/3/