單行文本溢出顯示省略號(hào)
width:20%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
WebKit瀏覽器或移動(dòng)端的頁(yè)面(多行溢出)
-webkit-line-clamp 用來(lái)限制在一個(gè)塊元素顯示的文本的行數(shù)癣缅。
為了實(shí)現(xiàn)該效果铛嘱,它需要組合其他的WebKit屬性。常見(jiàn)結(jié)合屬性:
- display: -webkit-box:必須結(jié)合的屬性 包个,將對(duì)象作為彈性伸縮盒子模型顯示 窗市。
- -webkit-box-orient: 必須結(jié)合的屬性 ,設(shè)置或檢索伸縮盒對(duì)象的子元素的排列方式 欠雌。
- text-overflow: ellipsis;可以用來(lái)多行文本的情況下,用省略號(hào)“…”隱藏超出范圍的文本 疙筹。
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
跨瀏覽器兼容的方案
比較靠譜簡(jiǎn)單的做法就是設(shè)置相對(duì)定位的容器高度富俄,用包含省略號(hào)(…)的元素模擬實(shí)現(xiàn);
p {
position:relative;
line-height:1.4em;
/* 3 times the line-height to show 3 lines */
height:4.2em;
overflow:hidden;
}
p::after {
content:"...";
font-weight:bold;
position:absolute;
bottom:0;
right:0;
padding:0 20px 1px 45px;
background:url(http://css88.b0.upaiyun.com/css88/2014/09/ellipsis_bg.png) repeat-y;
}