我有下表:
.myContainer {
background-color: yellow;
width: 200px;
}
.myTable {
}
.columnA {
max-width: 80px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.columnB {
}
.columnC {
}
<div class="myContainer">
<table class="myTable">
<th>
<tr>
<th>Name</th>
<th>Height</th>
<th>Weight</th>
</tr>
</th>
<tr>
<td class="columnA">Jack Jackman</td>
<td class="columnB">170.000</td>
<td class="columnC">70.000</td>
</tr>
<tr>
<td class="columnA">Smith Smithman</td>
<td class="columnB">180.000</td>
<td class="columnC">80.000</td>
</tr>
</table>
</div>
我需要摆脱固定max-width: 80px;
的.columnA
而不会丢失省略号效果。这样:
这是一种在其中添加额外divcolumnA
并将columnB
/columnC
设置为较小宽度的方法。
额外的div也需要具有position: absolute
,否则它将把所有内容推向右侧。
.myContainer {
background-color: yellow;
max-width: 200px;
}
.myTable {
width: 100%;
}
.columnA {
position: relative;
}
.columnA div {
position: absolute;
left: 0;
top: 0;
right: 0;
height: auto;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.columnB {
width: 10%;
}
.columnC {
width: 10%;
}
<div class="myContainer">
<table class="myTable">
<tr>
<th>Name</th>
<th>Height</th>
<th>Weight</th>
</tr>
<tr>
<td class="columnA"><div>Jack Jackman</div></td>
<td class="columnB">170.00</td>
<td class="columnC">70.000</td>
</tr>
<tr>
<td class="columnA"><div>Smith Smithman</div></td>
<td class="columnB">180.00000</td>
<td class="columnC">80.000</td>
</tr>
</table>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句