溢出时不出现点

时间:2018-07-06 11:20:46

标签: html css html-table overflow

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

我希望它像这样:长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>

3 个答案:

答案 0 :(得分:0)

请在代码中添加以下样式。

a {
  text-overflow: ellipsis;
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  display: inline-block;
}
<table>
  <tr>
    <td>short text</td>
    <td><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>

此外,如果您有跨度可以实现省略号,则不需要它。简单地将样式直接应用于锚标记

答案 1 :(得分:0)

.headlinesStyle {
  position: relative;
  overflow: hidden;
  display: block;
  height: 18px;
text-overflow: ellipsis;
width: 15%;
white-space: nowrap;
color: #333 !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>

.headlinesStyle {
  position: relative;
  overflow: hidden;
  display: block;
  width: 20%;
  height: 18px;
  white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
}

.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>

答案 2 :(得分:0)

您可以这样使用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/