css--兩行顯示省略號兼容火狐瀏覽器

1.固定的寬度,強制不換行,超出隱藏,顯示省略號


.ellipse1{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
.ellipse2{overflow:hidden; text-overflow:ellipsis;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;}

2.火狐下不兼容:

兼容做法:

p{position: relative; line-height: 20px; max-height: 40px;overflow: hidden;}
p::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%);
}

3.

  1. 將height設置爲line-height的整數倍,防止超出的文字露出。
  2. 給p::after添加漸變背景可避免文字只顯示一半。
  3. 由於ie6-7不顯示content內容,所以要添加標籤兼容ie6-7(如:<span>…<span/>);兼容ie8需要將::after替換成:after。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章