css3--單行、多行文本溢出


 1 <style>
 2 .div1 {
 3     width: 200px;
 4     height: 200px;
 5     background: red url(img/user.png) no-repeat;
 6     text-overflow: ellipsis;
 7     white-space: nowrap;
 8     overflow: hidden;
 9 }
10 .div1:hover {
11     overflow: visible;
12     text-overflow: inherit;
13 }
14                 
15 </style>
1 <div class="div1">
2         qwe Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae voluptatem sapiente fuga facere molestias numquam officiis beatae ex sit atque aspernatur quisquam commodi ratione perspiciatis ducimus dolor minima itaque obcaecati!
3 </div>

 

CSS實現單行、多行文本溢出顯示省略號

方法一:只顯示3行,在第三行結尾顯示...

1 p{display: -webkit-box;
2 -webkit-box-orient: vertical;
3 -webkit-line-clamp: 3;
4 overflow: hidden;
5 }

方法二:適用性更廣,未超出部分也會出現...

 1 p{
 2   position: relative;
 3   line-height: 20px; 
 4   max-height: 40px; /*是行高的整數倍,防止下行文字露出*/
 5   overflow: hidden;
 6 }
 7 
 8 p::after{
 9   content: "..."; position: absolute; bottom: 0; right: 0; padding-left: 40px;
10   background: -webkit-linear-gradient(left, transparent, #fff 55%);
11   background: -o-linear-gradient(right, transparent, #fff 55%);
12   background: -moz-linear-gradient(right, transparent, #fff 55%);
13   background: linear-gradient(to right, transparent, #fff 55%);
14 }    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM