如何截断固定宽度表格单元格中的文本?
我有一个包含 3 个表格单元格的表格。我的目标是为每个设置固定的宽度。如果 td 太长,中间的 td 也应该剪切文本,如果文本太长,则显示点。 (文本截断)
我尝试了不同的可能性(表固定、最大宽度等),但它仍然不起作用。也许有人可以帮助我。
/* table styles added by community for demonstration */
table {
table-layout: fixed;
width: 100%;
border: 1px solid #ccc;
}
td:nth-child(2) {
background: pink;
}
.cut-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
<table>
<td style="width: 10%">XXX</td>
<td style="width: 70%" class="cut-text">LOOOOOOOONG TEXT LOOOOOOOONG TEXT LOOOOOOOONG TEXT LOOOOOOOONG TEXT LOOOOOOOONG TEXT </td>
<td style="width: 20%">XXX</td>
</table>
普通表格如下所示:
如果中间的文本太长,我想显示像这样的点(我通过中间单元格中的 div 实现此目的。然后我设置 div 宽度并添加类“cut-text”。但是没有第三个单元格。)
也许有人可以帮助我。
亲切的问候。
I have a table with 3 table cells. My goal is to set a fixed width for each. The td in the middle should also cut the text if its to long for the td and show dots if the text is too long. (text-truncate)
I tried different possibilities (table-fixed, max-width etc.), but it still doesn't work. Maybe someone can help me.
/* table styles added by community for demonstration */
table {
table-layout: fixed;
width: 100%;
border: 1px solid #ccc;
}
td:nth-child(2) {
background: pink;
}
.cut-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
<table>
<td style="width: 10%">XXX</td>
<td style="width: 70%" class="cut-text">LOOOOOOOONG TEXT LOOOOOOOONG TEXT LOOOOOOOONG TEXT LOOOOOOOONG TEXT LOOOOOOOONG TEXT </td>
<td style="width: 20%">XXX</td>
</table>
The normal Table looks like this:
And if the text in the middle is to long I want to show dots like this (I achieve this with a div in the middle cell. Then I set the div width and added the class "cut-text". But then there is no third cell.)
Maybe someone can help me.
Kind regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论