3
下面是現有實現的link。顯示最大兩條線,並顯示後兩行只衰落
目前,我總是顯示衰落。如果用戶輸入了兩行以上,則需求將會消失。但是,如果有一行文本或兩行文本具有足夠的空間,則不會出現這種淡化。是否可以使用純CSS實現?
注:我不能設置固定高度的div有隻佔據一行的高度,如果用戶已經進入了只有一行。
.testWrapOverflowFade {
overflow: hidden;
position: relative;
height: 2.4em; /* NOL = height in this class/height in after class. Here it is 2.4/1.2 = 2. Change it to 3.6em for display 3 lines. */
}
.testWrapOverflowFade:after {
content: "";
text-align: right;
position: absolute;
bottom: 0;
right: 0;
width: 10%;
height: 1.2em;
background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
background: -moz-linear-gradient(left, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
background: -o-linear-gradient(left, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
}
<div class="testWrapOverflowFade">This is a long text this is a long text 2 this is a long text 3 this is a long text 4 this is a long text 5 this is a long text6 this is a long text7 this is a long text 8 this is a long text 9 this is a long text 10 this is a long text 11 this is a long text12 </div>
---- ---- UPDATE 這裏是懸停問題。我用黃色突出顯示它。
在此先感謝。
是的,完全一樣解決方法,我來得太晚了。大聲笑 – Anami
是的,它發生了:) – kukkuz
感謝您的幫助。我已經通過設置max-height和top來實現它,但問題是我對於懸停時的淡化有特殊效果。每當我徘徊在該div上時,我都能看到褪色的特殊效果。我不確定爲什麼它沒有像JSFiddle中發生的那樣隱藏起來。 –