如何截断表格单元格,但尽可能多地容纳内容?

新手上路,请多包涵

认识弗雷德。他是一张桌子:

一个单元格内容较多且较宽,另一个单元格内容较少且较窄

 <table border="1" style="width: 100%;">
    <tr>
        <td>This cells has more content</td>
        <td>Less content here</td>
    </tr>
</table>

弗雷德的公寓有一个奇怪的改变大小的习惯,所以他学会了隐藏他的一些内容,以免把所有其他单元推到一边,把惠特福德夫人的客厅推到遗忘的地方:

这些单元格现在大小相同,但只有一个单元格的内容被截断,看起来如果另一个单元格给出一些空格,它们都可以容纳。

 <table border="1" style="width: 100%; white-space: nowrap; table-layout: fixed;">
    <tr>
        <td style="overflow: hidden; text-overflow: ellipsis">This cells has more content</td>
        <td style="overflow: hidden; text-overflow: ellipsis">Less content here</td>
    </tr>
</table>

这行得通,但 Fred 有一种挥之不去的感觉,如果他的右侧单元格(他的昵称是 Celldito)让出一点空间,他的左侧单元格就不会经常被截断。你能拯救他的理智吗?


总结:表格的单元格如何才能均匀地溢出,并且只有当它们都放弃了所有空白时?

原文由 s4y 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 561
1 个回答
<table border="1" style="width: 100%;">
    <colgroup>
        <col width="100%" />
        <col width="0%" />
    </colgroup>
    <tr>
        <td style="white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:1px;">This cell has more content.This cell has more content.This cell has more content.This cell has more content.This cell has more content.This cell has more content.</td>
        <td style="white-space: nowrap;">Less content here.</td>
    </tr>
</table>

http://jsfiddle.net/7CURQ/

原文由 ladislav 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题