css实现单行和多行省略号
2024-09-25 08:37:15
1.单行省略
{
width:300px;
overflow: hidden;
text-overflow:ellipsis;
whitewhite-space: nowrap;
}
注:单行省略必须设置宽度
2.多行省略
{
display:-webkit-box;
overflow:hidden;
text-overflow:ellipsis;
-webkit-line-clamp:;
-webkit-box-orient:vertical;
}
以上方式存在兼容问题,只有带webkit内核的浏览器才兼容
<div class="container">
<div class="text">
dsasssssefewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwfvffdassssssssssssssssssss
</div>
</div>
.container{
height: 40px;
line-height: 20px;
width: 100%;
overflow: hidden;
}
.container .text{
float: right;
margin-left: -15px;
width: 100%;
color: #000;
word-break: break-all;
word-wrap: break-word;
}
.container::before{
float:left;
width: 15px;
content: '';
height: 40px;
}
.container::after{
float: right;
content: '...';
height: 20px;
line-height: 20px;
width: 3em;
text-align: right;
margin-left: -3em;
position: relative;
left: 100%;
top:-20px;
padding-right: 15px;
background: -webkit-linear-gradient(left, transparent, #fff 52%);
background: -o-linear-gradient(rightright, transparent, #fff 52%);
background: -moz-linear-gradient(rightright, transparent, #fff 52%);
background: linear-gradient(to rightright, transparent, #fff 52%);
}
::before占了一个位置,为了让::after显示的内容在右边显示作铺垫,float:right为了让省略号在不溢出的情况下在最右边显示,::after 中position:relative;left:100% 是为了当溢出时,省略号在最右边显示
该方法兼容良好,适合各大主流浏览器
最新文章
- 数据结构图文解析之:哈夫曼树与哈夫曼编码详解及C++模板实现
- 新年PR交期回写,展望期由14天改为30天,FP_PR2SAP ;转单量改为100W;FP_PR2SAP_MOD_NEW
- ubuntu server设置时区和更新时间
- python numpy笔记:给matlab使用者
- linux sed使用
- Jenkins学习之——(4)Email Extension Plugin插件的配置与使用
- 5s
- SQL Server-索引故事的遥远由来,原来是这样的?
- accp8.0转换教材第5章事务、视图、索引、备份和恢复理解与练习
- (转)spring学习之@ModelAttribute运用详解
- 二叉树的递归遍历 Tree UVa548
- Dagoin之modelform组件
- HDU 6437 Problem L.Videos (最大费用)【费用流】
- js点击复制剪贴板
- 自己动手写Android插件化框架,让老板对你刮目相看
- LOJ #2058「TJOI / HEOI2016」求和
- Python_set集合部分功能介绍
- 关于tpg例程的仿真
- DevExpress GridControl小结
- 为什么和什么是 DevOps?
热门文章
- 中国城市区号脚本-mysql
- shell 预定义变量
- codeforces div2_603 F. Economic Difficulties(树dfs预处理+dp)
- VSFTPD服务器
- js基础心得
- django 模型增加字段后迁移失败
- apache http server 和tomcat的区别 以及nginx
- [lua]紫猫lua教程-命令宝典-L1-01-11. lua的个人补充
- 2019牛客多校第二场F Partition problem 暴力+复杂度计算+优化
- TCP协议的3次握手与4次挥手过程【深度详解】