2016-04-13 24 views
0

我有一個線程,並希望爲每個線程預覽文本。就像這樣:3行長html預覽文本

How I can loose weight? <- Headline 
bla bla bla bla bla  | 
bla bla bla bla bla  | <- Preview 
bla bla bla bla bla... | 

我想那裏結束三行預覽文字是簡單地用「......」 我試了一下:

.p { 
color: grey; 
text-overflow: ellipsis; 
overflow: hidden; 
word-wrap: break-word; 
line-height: 16px; 
max-height: 32px; 
} 

但是這並沒有爲我工作。有沒有人知道這個解決方案?也許與JS或JQuery?

+2

請分享你的html結構cture也 –

+1

見https://css-tricks.com/line-clampin/ –

+0

'我怎樣才能減輕體重?'http://www.health.com/health/gallery/0,20501331,00.html –

回答

1

It works, see it here

.p { 
    color: grey; 
    text-overflow: ellipsis; 
    overflow: hidden; 
    white-space: nowrap; 
    line-height: 16px; 
} 

編輯

這是一種使壞,使之適合於3線, 「...」 到底內容:

.p { 
    color: grey; 
    overflow: hidden; 
    height: 50px; 
    line-height: 16px; 
    position: relative; 
    word-wrap: break-word; 
} 

.p:after { content: "..."; background: #f3f5f6; position :absolute; right: 0; bottom: 2px;} 

See it here

+0

由於'white-space:nowrap',這隻會是一條線,儘管 –

+0

不是。這只是一條線。我想要預覽長度爲3行,以'...'結尾 – WellNo

+1

@Rory McCrossan你說得對。我已經更新了我的答案,使其適合3行。 –