CSS 超出部分顯示省略號
阿新 • • 發佈:2018-12-31
單行超出顯示省略號
直接看程式碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>desktop demo</title>
<style>
.app {
width: 400px;
height: 28px;
line-height: 28px;
margin: 50px 0 0 50px;
border: 1px solid red;
white-space : nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="app">
<span class="content">你問我為何時常沉默,有的人無話可說,有的話無人可說.你問我為何時常沉默,有的人無話可說,有的話無人可說.</span>
</div>
</body>
</html>
效果圖:
關鍵點:
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
多行超出顯示省略號
直接看程式碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>desktop demo</title>
<style>
.content {
display: -webkit-box;
width: 400px;
line-height: 1.5;
margin: 50px 0 0 50px;
border: 1px solid red;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
</style>
</head>
<body>
<div class="app">
<span class="content">你問我為何時常沉默,有的人無話可說,有的話無人可說.你問我為何時常沉默,有的人無話可說,有的話無人可說.
</span>
</div>
</body>
</html>
效果圖:
關鍵點:
display: -webkit-box;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
---------------------------(正文完)------------------------------------
一個前端的學習交流群,想進來面基的,可以點選這個logo,或者手動search群號:685486827
--------------------------------(完)--------------------------------------
更多學習資源請關注我的新浪微博…