纯css实现文本溢出省略号,兼容(火狐,IE9,chrome)

很多业务需求下会出现文本溢出无法显示的情况,设置为显示省略号又不兼容,兼容性只能用js实现,今天介绍一种可以直接用css实现的方法。该方法兼容各大主流浏览器,除了诡异的IE低版本

实现原理:盒模型浮动原理

实现代码源码:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>多行文本实现省略号显示</title>
</head>
<style type="text/css">
    /*纯css实现省略号,兼容火狐,IE9,chrome*/
	.wrap{
		height:40px;line-height:20px;overflow: hidden;width:500px;background:#999;
	}
	.wrap .text{
		float:right;margin-left:-5px;width:500px;word-break: break-all;
	}
	.wrap::before{
		float:left;width:5px;content:'';height:40px;
	}
	.wrap::after{
		float:right;content:'...';height:20px;line-height:20px;
		width:30px;margin-left:-30px;/*更改宽度和边距,移动省略号位置*/
		position:relative;left:100%;top:-20px;
		padding-right:5px;background:#999;
	}
</style>
<body>
	<div class="wrap">
		<div class = "text">
			ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试ceshi测试
		</div>
	</div>
</body>
</html>

有更好的方法可以交流

版权声明:转载请注明出处 https://blog.csdn.net/qdmoment/article/details/84971312

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值