aka*_*ash 6 html css google-chrome
为什么-webkit-line-clamp没有显示正确的省略号text-align:justify。它与 一起工作得很好text-align:left/right。
请提出任何技巧。
div {
text-align: justify;
width:150px;
padding: 0 5px;
line-height: 18px;
display: -webkit-box;
display: -moz-box;
display: -ms-box;
max-width: 100%;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}Run Code Online (Sandbox Code Playgroud)
<div>Why Line Clamp is not working with text align justify</div>Run Code Online (Sandbox Code Playgroud)
您尝试使用的解决方案是一种非常古老的技术。它使用旧版本的display: flex;, 应避免使用。
您可以使用JavaScript技术clamp.js,但我也创建了这个纯CSS版本:http://codepen.io/n3ptun3/pen/meYKgZ? editors=110
CSS
p {
position: relative;
width: 400px;
height: 120px;
line-height: 30px;
margin: 0px;
padding: 0px;
overflow: hidden;
text-align: justify;
}
p::after {
content: "...";
background-color: #fff;
height: 30px;
width: 20px;
position: absolute;
bottom: 0;
right: 0;
}
Run Code Online (Sandbox Code Playgroud)
当然,这只适用于纯色背景,但大多数情况下,正文都是这种情况。
以下是要点: