CSS percentage width and text-overflow in a table cell

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I have a table where the cells' width is in percentage and I want to use text-overflow: ellipsis to hide long lines of text:

http://jsfiddle.net/Fm5bM/

In the example the ellipsis works fine in a div but not in the cell. It still grows and ignores both width:60% and max-width:60%.

If I add a display:block to the cell, the text does stop at 60% and gets the ellipsis, but the total width of the cell is still the size of the whole text.

http://jsfiddle.net/Fm5bM/3/

Ultimately, I want the table to fit the screen. Is there a way to do it with pure css?

回答1:

This is easily done by using table-layout: fixed, but "a little tricky" because not many people know about this CSS property.

table {   width: 100%;   table-layout: fixed; } 

See it in action at the updated fiddle here: http://jsfiddle.net/Fm5bM/4/



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!