html 文字在第二行超出,css – 如何进行文本溢出:两行省略?

这篇博客介绍了如何通过CSS实现文本超出容器时显示省略号的效果。通过设置.container的overflow为hidden,position为relative,背景颜色等属性,然后利用伪元素:after创建省略号,并通过定位和内容属性完成布局。这种方法适用于现代浏览器,可以在调整容器大小时动态显示省略号。
摘要由CSDN通过智能技术生成

向容器添加一个span,它将保存文本:

text...

添加此CSS:

.container {

overflow: hidden;

position: relative;

background: white; //or other color

}

.container:after {

content: '...'; //the ellipsis

position: absolute; //positioned in bottom-right

bottom: 0; //...

right: 0; //...

padding: 0 0.3em; //give some separation from text

background: inherit; //same color as container

}

.container span:after {

content: '\0000a0'; //a space

position: absolute; //to cover up ellipsis if needed

width: 1000px; //...

z-index: 1; //...

background: white; //must match container's color. can't use inherit here.

}

调整容器大小,您将看到省略号仅在必要时显示.

应该适用于所有现代浏览器.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值