自己对知识的了解,留作面试用,如有错误请指正
单行文字:
<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{
/* 设置宽度 */
width: 100px;
/* 强制文本在一行显示 */
white-space: nowrap;
/* 隐藏溢出的部分 */
overflow: hidden;
/* 省略表示 */
text-overflow: ellipsis;
/* height: 50px; */
background-color: aqua;
}
</style>
</head>
<body>
<!-- <p>自己对知识的了解,留作面试用,如有错误请指正</p> -->
<div class="box">自己对知识的了解,留作面试用,如有错误请指正</div>
</body>
</html>
多行文字: display:-webkit-box
<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{
/* 设置宽度 */
width: 100px;
height: 60px;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
/* 第几行开始省略 */
-webkit-line-clamp: 3;
background-color: aqua;
}
</style>
</head>
<body>
<!-- <p>自己对知识的了解,留作面试用,如有错误请指正</p> -->
<div class="box">自己对知识的了解,留作面试用,如有错误请指正</div>
</body>
</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{
/* 设置宽度 */
width: 200px;
height: 50px;
overflow: hidden;
position: relative;
text-align: center;
padding-right: 1em;
background-color: aqua;
}
.box::before{
content: '...';
position:absolute;
bottom: 0;
right: 0;
}
.box::after{
content: '';
background-color: aqua;
width: 1em;
height: 1em;
position: absolute;
display: inline;
right: 0;
margin-top: 0.5em;
}
</style>
</head>
<body>
<!-- <p>自己对知识的了解,留作面试用,如有错误请指正</p> -->
<div class="box">知识的了解,留作面试用,如有错误请指正自己对知识的了解,留作面试用,如有错误请指正,如有错误请指正</div>
</body>
</html>