2013-05-01 39 views
1

我有一張桌子。它的<td>overflow: hidden。當我有一個長度超過100px的字符串時,它不會被隱藏。如何隱藏​​中的溢出?

如何隱藏內容超過其容器的寬度時<td>

http://jsfiddle.net/be6tM/

+0

的可能重複[爲什麼溢出:隱藏不顯示在​​工作(http://stackoverflow.com/questions/509711/why-does-overflowhidden-not-work-in-a- td) – adrianbanks 2013-05-01 23:17:41

+0

'text-overflow:ellipsis' [也很有趣](http://jsfiddle.net/be6tM/8/)。 – Ryan 2013-05-01 23:24:04

回答

2

默認行爲只是包裝文本,因爲高度沒有問題!儘管如此,您可以禁用文字換行,white-space: nowrap

但是,由於表格有點特殊,您需要使用max-width而不是width(這只是「首選寬度」)。 Here’s your updated jsFiddle.

td { 
    border: 1px solid rgb(0,0,0); 
    max-width: 100px; 
    overflow: hidden; 
    white-space: nowrap; 
}
1

沒有溢出。設置高度以限制單元格的高度,那麼任何佔用更多垂直空間的東西都應該溢出。