博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
css单行文本和多行文本溢出实现省略号显示
阅读量:6955 次
发布时间:2019-06-27

本文共 1314 字,大约阅读时间需要 4 分钟。

1、单行文本溢出

 文本内容

  HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld

固定文本宽度,且保证文本不换行,溢出的部分隐藏,设置text-overflow为ellipsis则溢出的文本以省略号显示

.singleLine{
width:200px; padding: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}

显示效果如图

2、多行文本溢出

 文本内容

HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld HelloWorld

多行文本显示时通过-webkit-line-clamp设置显示的行数,并且设置display为-webkit-box,-webkit-box-orient为vertical

.multiLine{
width:200px; padding:0 10px; overflow : hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

显示效果

 3、跨浏览器

.imitate_ellipsis{
position:relative; line-height:1.4em; height:2.8em; overflow:hidden; width:200px; }.imitate_ellipsis::after{
content:"..."; font-weight:bold; position:absolute; bottom:0; right:0; padding-left:20px; background: -webkit-linear-gradient(left, transparent, #fff 0%); background: -o-linear-gradient(right, transparent, #fff 0%); background: -moz-linear-gradient(right, transparent, #fff 0%); background: linear-gradient(to right, transparent, #fff 0%);}

通过伪类::after在文本后加入省略号

转载于:https://www.cnblogs.com/lhyhappy365/p/9430428.html

你可能感兴趣的文章
hadoop2.4 支持snappy
查看>>
STL 笔记(四) 迭代器 iterator
查看>>
2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】
查看>>
[LeetCode] Valid Parenthesis String 验证括号字符串
查看>>
各大SRC中的CSRF技巧
查看>>
Docker for Windows 使用入门
查看>>
【Django】Web应用开发经由
查看>>
SpringBoot(九)-- SpringBoot JDBC
查看>>
Spring + Mybatis - 原始dao开发整合 与 Mapper代理整合
查看>>
基于Centos搭建nginx+uwsgi运行django环境
查看>>
context switch
查看>>
Oracle awr报告生成操作步骤
查看>>
【DB2】DB2使用IMPORT命令导入含有自增长列的表报错处理
查看>>
微服务之springCloud-docker-comsumer(三)
查看>>
dhcpcd守护进程分析【转】
查看>>
Linux - 理不清的权限chmod与chown区别
查看>>
TCP协议疑难杂症全景解析
查看>>
redis 1
查看>>
Python安装pycurl失败,及解决办法
查看>>
cocos2d的常用动作及效果总结之四:Special Actions
查看>>