html - 溢出 :hidden dots at the end

标签 html css

假设我有一个字符串“我喜欢大屁股,我不能说谎”,我用 overflow:hidden 将它剪掉,所以它显示如下:

I like big butts and I cann

截断文字。是否可以这样显示:

I like big butts and I cann...

使用 CSS?

最佳答案

您可以使用 text-overflow: ellipsis;其中according to caniuse所有主流浏览器都支持。

这里是 a demo在 jsbin 上。

.cut-text { 
  text-overflow: ellipsis;
  overflow: hidden; 
  width: 160px; 
  height: 1.2em; 
  white-space: nowrap;
}
<div class="cut-text">
I like big butts and I can not lie.
</div>

关于html - 溢出 :hidden dots at the end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/486563/

相关文章:

asp.net - TreeView CSS 友好输出?控制适配器? ASP.NET 3.5

html - 图片后面的 href 链接在 ie 中不起作用

javascript - CSS/Javascript 菜单固定位置问题(滚动时)

html - LessCSS - 将颜色评估为内容的字符串

javascript - 带有 HTML5 Dialog .showModal() 方法的 reCAPTCHA v2

javascript - 在 Jquery load() 之后设置 div 的高度

javascript - 在表单的高度隐藏粘滞按钮

css - z-index 奇怪的行为?

html - 为什么 h2 中的 img 会在另一个显示 :table divs 中导致额外的顶部填充

javascript - 让 Magento 类别返回 false