<!doctype html><html><body>
<style>
.ellipsis {
overflow: hidden;
position: relative;
}
.ellipsis-more-top {/*push down .ellipsis-more*/
content: "";
float: left;
width: 5px;
}
.ellipsis-text-container {
float: right;
width: 100%;
margin-left: -5px;
}
.ellipsis-more-container {
float: right;
position: relative;
left: 100%;
width: 5px;
margin-left: -5px;
border-right: solid 5px transparent;
white-space: nowrap;
}
.ellipsis-placeholder {/*keep text around ,keep it transparent ,keep same width and height as .ellipsis-more*/
float: right;
clear: right;
color: transparent;
}
.ellipsis-placeholder-top {/*push down .ellipsis-placeholder*/
float: right;
width: 0;
}
.ellipsis-more {/*ellipsis things here*/
float: right;
}
.ellipsis-height {/*the total height*/
height: 3.6em;
}
</style>
<p class="ellipsis ellipsis-height ellipsis-line-height">
<p class="ellipsis-more-top ellipsis-height"></p>
<p class="ellipsis-text-container">
<p class="ellipsis-placeholder-top ellipsis-height ellipsis-margin-top"></p>
<p class="ellipsis-placeholder">
<span>...</span><span>more</span>
</p>
<span class="ellipsis-text">text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </span>
</p>
<p class="ellipsis-more-container ellipsis-margin-top">
<p class="ellipsis-more">
<span>...</span><span>more</span>
</p>
</p>
</p>
</body></html>
比较靠谱简单的做法就是设置相对定位的容器高度,用包含省略号(…)的元素模拟实现;
text-overflow: ellipsis;
刚去caniuse上看了下,除了firefox最早期的几个版本不支持之外,其他的都支持的
如果需要跨内核支持,允许固定高的可以借助多层嵌套浮动这么做:
如需不定高,可借助
line-clamp
和float
可以在webkit上实现自适应高的定制的多行省略,详细解释看黑科技:CSS定制多行省略