CSS(文本溢出 : ellipsis) -- a shorter way?

标签 css

文本省略号有更短的方法吗?只是一个提示,但它似乎最多只需要宽度和文本溢出吗?

width: (whatever);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;

最佳答案

CSS 中的 text-overflow 属性处理文本溢出元素框时被剪裁的情况。它可以被剪裁(即切断、隐藏)、显示省略号 ('…', Unicode Range Value U+2026) 或显示作者定义的字符串(当前浏览器不支持作者定义的字符串)。

请注意,仅当容器的溢出属性的值为 hiddenscrollautowhite- 时,才会发生 text-overflow空格:nowrap;.

.overflow {
  width: 10em;
  outline: 1px solid #000;
  margin: 0 0 2em 0;
  /**
   * Required properties to achieve text-overflow
   */
  white-space: nowrap;
  overflow: hidden;
}

body style {
  display: block;
  font: 14px monospace;
  padding: 3px;
  margin: 0 0 5px 0;
}
<style>
  .clip {
    text-overflow: clip;
  }
</style>
<p class="overflow clip">This is an example text showing nothing interesting but the truncated content via text-overflow shorthand property.</p>

<style>
  .ellipsis {
    text-overflow: ellipsis;
  }
</style>
<p class="overflow ellipsis">This is an example text showing nothing interesting but the truncated content via text-overflow shorthand property.</p>

<style>
  .word {
    text-overflow: ellipsis-word;
  }
</style>
<p class="overflow word">This is an example text showing nothing interesting but the truncated content via text-overflow shorthand property.</p>

<style>
  .text {
    text-overflow: "---";
  }
</style>
<p class="overflow text">This is an example text showing nothing interesting but the truncated content via text-overflow shorthand property.</p>

<style>
  .double {
    text-overflow: ellipsis ellipsis;
    text-align: center;
  }
</style>
<p class="overflow double">This is an example text showing nothing interesting but the truncated content via text-overflow shorthand property.</p>

关于CSS(文本溢出 : ellipsis) -- a shorter way?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45287815/

相关文章:

javascript - 如何设置 jQuery Select2 组合框容器的样式?

html - 样式化多个 :select dropdowns to display inline

html - 内容未将页脚向下推

html - 无法使站点在不同浏览器中正确显示

css - 2.3 Nopcommerce 主题更新到3.0了?

javascript - 使图像成为下拉菜单

html - IE 6 和 7 中的流体宽度布局问题

css - rails 上的 ruby : stylesheet in assets doesn't works

php多变量验证

html - 输入字段按钮的动态工具提示的最佳方式