我有一个动态加载数据的表格,当单元格中的文本很大时,我想用省略号将它包裹起来,并且在鼠标悬停时优雅地显示完整的数据。 目前我只是使用HTML和CSS来做这件事,我的问题是使用下面的CSS,即使数据不是很大(宽度和省略号),鼠标悬停时的样式仍然会出现。有没有解决方法?或者有没有更好的方法来使用JavaScript来做到这一点?如何以用户友好的方式在表格中显示溢出文本?
这是我创建的重击者。在第三栏中,您可以看到文本不是很大,没有省略号但样式仍然适用。任何帮助深表感谢!
https://plnkr.co/edit/cDOxlXRK6QfynVdpCbCT?p=preview
我的CSS低于:
/* Styles go here */
table td.text {
max-width: 10px;
}
table td.text span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 100%;
}
table td.text:hover span{
border: 2px solid #000000;
background-color: #ffffff;
padding: 5px;
overflow: visible;
white-space: normal;
height: auto;
/* just added this line */
position:absolute;
}
table td.text:hover span:empty {
display:none;
}
我的HTML低于:
<table>
<thead>
<tr class="text-center">
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
</tr>
</thead>
<tr>
<td class="text"><span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</span></td>
<td class="text"><span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</span></td>
<td class="text"><span>Lorem </span></td>
<td class="text"><span></span></td>
</tr>
</table>
有没有办法使用工具提示来做到这一点? –