單/行文字溢出省略

常規做法

html

<p class="text"></p>

css

/*單行*/
.text {
	overflow: hidden;
	text-overflow:ellipsis;
	white-space: nowrap; 
}
/*多行*/
.text {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3; //行數 
	overflow: hidden; 
}

兼容性做法

.text{
	position: relative;
	line-height: 20px;
	max-height: 40px;
	overflow: hidden;
}
text::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%); 
}
發佈了25 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章