css實現單行文本溢出顯示…
效果圖如下:
實現方法:
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
還需要加寬度width屬來兼容部分瀏覽。
css實現多行文本溢出顯示…
效果圖如下:
實現方法:
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
1、-webkit-line-clamp用來限制在一個塊元素顯示的文本的行數。 爲了實現該效果,它需要組合其他的WebKit屬性。常見結合屬性:
2、display: -webkit-box; 必須結合的屬性 ,將對象作爲彈性伸縮盒子模型顯示 。
3、-webkit-box-orient 必須結合的屬性 ,設置或檢索伸縮盒對象的子元素的排列方式 。
css實現多行文本溢出顯示…(超出過度漸變消失)
效果圖如下:
實現方法:
div {
position: relative;
line-height: 20px;
max-height: 40px;
overflow: hidden;
}
div:after {
content: "..."; position: absolute; bottom: 0; right: 0; padding-left: 40px;
background: -webkit-linear-gradient(left, transparent, #fff 55%);
background: -o-linear-gradient(right, transparent, #fff 55%);
background: -moz-linear-gradient(right, transparent, #fff 55%);
background: linear-gradient(to right, transparent, #fff 55%);
}