我有一个使用省略号的表,但我坚持使用相互矛盾的争论。场景是我有一个带有tr标签和2 td的表。我需要第一个td是文本的宽度(border-collapse:collapse),这很好,但是,我需要表的宽度为100%所以在第二个td我可以使用省略号。我还没有找到一种方法来对第一个td进行边界折叠,并将第二个用作省略号。
http://jsfiddle.net/epywtvjf/2/
<table>
<tr>
<td>This is the first div.
</td>
<td>This is the second div. This is the second div.This is the second div. This is the second div. This is the second div.
</td>
</tr>
<tr>
<td>This is the first div.
</td>
<td>This is the second div. This is the second div.This is the second div. This is the second div. This is the second div.
</td>
</tr>
<tr>
<td>This is the first div.
</td>
<td>This is the second div. This is the second div.This is the second div. This is the second div. This is the second div.
</td>
</tr>
</table>
table{
table-layout: fixed;
width: 100%;
border-collapse: collapse;
}
table td{
white-space: nowrap;
border: none;
line-height:unset;
padding: 0px;
text-align: left;
}
答案 0 :(得分:1)
您可以通过在html中向td添加一个类然后使用。来为每个td指定特定的css。 css中的类选择器。
<table>
<tr>
<td class="col1">This is the first div.
</td>
<td class="col2">This is the second div. This is the second div.This is the second div. This is the second div. This is the second div.
</td>
</tr>
</table>
table {
table-layout: fixed;
border-collapse: collapse;
width: 100%;
}
td{
white-space: nowrap;
border: none;
padding: 0px;
text-align: left;
border-collapse: collapse;
overflow: hidden;
}
.col2 {
text-overflow: ellipsis;
}
答案 1 :(得分:1)
您可能需要在tr中添加display flex。以下css对我有用。
table {
table-layout: fixed;
border-collapse: collapse;
width:100%;
}
tr{
display: flex;
}
td{
white-space: nowrap;
border: none;
padding: 0px;
text-align: left;
border-collapse: collapse;
}
#td2 {
overflow:hidden;
text-overflow: ellipsis;
}
答案 2 :(得分:0)
更改表格布局:固定和溢出:隐藏? 这会解决你的问题吗? here