当前位置:网站首页>文字超出部分变成省略号的三种方式
文字超出部分变成省略号的三种方式
2022-07-21 18:01:00 【妈妈说名字太长的话躲树后面会被部落发现】
目录
1.单行文本溢出显示省略号
.box {
/*强制文本在一行内显示*/
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
/*强制文本在一行内显示*/
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100px;
}
</style>
</head>
<body>
<div class="box">啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊</div>
</body>
</html>
2.多行文本溢出显示省略号
.box {
overflow: hidden;
text-overflow: ellipsis;
/* 将对象作为弹性伸缩盒子模型显示 */
display: -webkit-box;
/* 限制在一个块元素显示的文本的行数 */
/* -webkit-line-clamp 其实是一个不规范属性,使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;*/
-webkit-line-clamp: 2;
/* 设置或检索伸缩盒对象的子元素的排列方式 */
-webkit-box-orient: vertical;
}
实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
overflow: hidden;
text-overflow: ellipsis;
width: 200px;
/* 将对象作为弹性伸缩盒子模型显示 */
display: -webkit-box;
/* 限制在一个块元素显示的文本的行数 */
/* -webkit-line-clamp 其实是一个不规范属性,使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;*/
-webkit-line-clamp: 2;
/* 设置或检索伸缩盒对象的子元素的排列方式 */
-webkit-box-orient: vertical;
}
</style>
</head>
<body>
<div class="box">啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊</div>
</body>
</html>
多行文本内容英语单词不太合适,下面的也是。
3.利用伪类实现省略号
.t3{
position: relative;
height: 40px;
line-height: 20px;
overflow: hidden;
}
.t3::after{
content: '...';
position: absolute;
bottom: 0;
right: 0;
padding-left: 40px;
background: linear-gradient(to right, transparent, #fff 55%);
}
实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.t3{
width: 200px;
position: relative;
height: 40px;
line-height: 20px;
overflow: hidden;
}
.t3::after{
content: '...';
position: absolute;
bottom: 0;
right: 0;
padding-left: 40px;
background: linear-gradient(to right, transparent, #fff 55%);
}
</style>
</head>
<body>
<div class="t3">省略号的位置可以通过定位调整啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊</div>
</body>
</html>
边栏推荐
- 写了2个月的借贷系统的心得
- 分省市县地理空间矩阵:地级市空间、地理距离矩阵等多指标数据集
- 4000+上市公司所属省份、城市、经营等多指标数据已更新至2022.1
- High frequency leetcode deep search part: 297 Serialization and deserialization of binary tree
- 高频leetcode深搜部分:124. 二叉树中的最大路径和
- 聊天室项目
- Redis原理之HyperLogLog
- Pointer of C language (1)
- Literature: Axure (brief introduction)
- performance 优化
猜你喜欢
随机推荐
Eight (variable) basic types
Pointer of C language (4)
The complement of position operation and shaping in C language
八大(变量)基本类型
数组
数学运算
Axure 中继器
Mathematical operation
1989-2020年学历结构和计算平均受教育年限数据
如何快速的学习嵌入式
文献: Axure(简单介绍)
数组的复制和数组地址值的复制
飞机躲子弹小游戏案例
Docker系列 六. Docker 安装 Redis
字节流
MVP_用户登录实例2_测试用例
嵌入式问题排查手段、网络问题、SD卡问题、设备启动问题、串口问题、i2c问题、spi问题、pcie等等问题
High frequency leetcode deep search part: 98 Validate binary search tree
Pointer of C language (3)
各地级市-进出口与贸易差额(2000-2020)