html - 溢出时不出现点

标签 html css html-table overflow

我有一个表格,中间的单元格包含长文本。 我发现下面的 CSS 理论上应该防止文本溢出并在末尾添加一些点。它确实防止它溢出,但是没有点。你能帮我理解为什么吗?

我希望它是这样的:long tex...

.headlinesStyle {
  position: relative;
  overflow: hidden;
  display: block;
  width: 100%;
  height: 18px;
  white-space: normal;
  color: transparent !important;
}

.headlinesStyle::selection {
  color: transparent !important;
}

.headlinesStyle:before {
  content: attr(data-cutwrap);
  position: absolute;
  left: 0;
  right: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #333;
}
<table>
  <tr>
    <td>short text</td>
    <td><span class='headlinesStyle'><a href="http...">LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT </a></span></td>
    <td>short</td>
  </tr>
</table>

最佳答案

您可以通过使用 white-spacetext-overflow 来实现这一点,如下所示:

.dots {
    max-width: 300px;
    overflow:hidden; 
    white-space:nowrap; 
    text-overflow: ellipsis;
    color: black; //if you want to color the dots
}


<table>
  <tr>
    <td>short text</td>
    <td class="dots"><a href="http...">LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXT LONG TEXTTEXTTEXTTEXTTEXTTEXT </a></td>
    <td>short</td>
  </tr>
</table>

这是一个有效的 jsfiddle:http://jsfiddle.net/o24b6w0u/2/

关于html - 溢出时不出现点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51209296/

相关文章:

javascript - 如何为html div启用键盘事件?

javascript - 如何在 x 秒后自动重新加载页面并重新提交表单数据

javascript - 将鼠标悬停在图像上时 qTip 不起作用

css - 对齐 html 表格内的文本

html - CSS 显示表格与普通 HTML 表格

javascript - 如何从下拉边框底部删除边框颜色?

html - CSS跨浏览器图像对齐问题

javascript - 带有用于垂直滚动的水平控件的 HTML 滚动框

css - 为什么 border 会影响 CSS 中的包含 block 大小?

javascript - 取消隐藏表格行会导致表格跳转,如何解决这个问题?