附加到由文本溢出省略号缩短的字符串

时间:2018-03-23 19:12:01

标签: javascript css sass

我想在引号中干净地显示一个用省略号缩短的字符串,例如,字符串是一个不应该完全显示为"a long sentence..."的长句子。

但是,当我使用文本溢出提供的省略号时:它将呈现为"a long sentence... "。如何删除省略号中包含的额外空格?

1 个答案:

答案 0 :(得分:1)

直接从这里采取的示例:text-overflow

我删除了段落上的填充。正如您所看到的,没有额外的空间"



p {
  width: 200px;
  border: 1px solid;
  padding: 0;

  /* BOTH of the following are required for text-overflow */
  white-space: nowrap;
  overflow: hidden;
}

.overflow-visible {
  white-space: initial;
}

.overflow-clip {
  text-overflow: clip;
}

.overflow-ellipsis {
  text-overflow: ellipsis;
}

.overflow-string {
  /* Not supported in most browsers, 
     see the 'Browser compatibility' section below */
  text-overflow: " [..]"; 
}

<p class="overflow-visible">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p class="overflow-clip">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p class="overflow-ellipsis">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p class="overflow-string">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
&#13;
&#13;
&#13;