css不受高度限制實現文本超出隱藏並以省略號結束


 

文本超出省略號顯示代碼:

overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
width: 100px; /*寬度做好限制*/

文本文本文本文本文本...

 

不考慮兼容性的,適用於WebKit瀏覽器內核的

 

width: 100px;
height: 65px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; /*截取到第三行*/ overflow: hidden;

 

文本文本文本文本文本

文本文本文本文本文本

文本文本文本文本文...

 

容器設置溢出隱藏、並手動設置生成一個內容為“...”的偽元素
 .box {
            width: 400px;
            height: 100px;
            margin: 100px auto;
            border: 1px solid #ccc;
            position: relative;
            line-height: 20px;
            overflow: hidden;
        }

        .box::after {
            content: "...";
            position: absolute;
            bottom: 0;
            right: 0;
            padding-left: 10px;
            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%);
        }

效果同上

 


免責聲明!

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



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