How can I do text-overflow: ellipsis on two lines?

前端 未结 4 618
半阙折子戏
半阙折子戏 2020-12-10 07:04

I have a container where the text may expand to two lines and it\'s 40px in height, with an 18px font size. When I do:

text-overflow: ellipsis;
white-space:          


        
4条回答
  •  暖寄归人
    2020-12-10 07:41

    a pure css method base on -webkit-line-clamp:

    @-webkit-keyframes ellipsis {/*for test*/
        0% { width: 622px }
        50% { width: 311px }
        100% { width: 622px }
    }
    .ellipsis {
        max-height: 40px;/* h*n */
        overflow: hidden;
        background: #eee;
    
        -webkit-animation: ellipsis ease 5s infinite;/*for test*/
        /**
        overflow: visible;
        /**/
    }
    .ellipsis .content {
        position: relative;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-box-pack: center;
        font-size: 50px;/* w */
        line-height: 20px;/* line-height h */
        color: transparent;
        -webkit-line-clamp: 2;/* max row number n */
        vertical-align: top;
    }
    .ellipsis .text {
        display: inline;
        vertical-align: top;
        font-size: 14px;
        color: #000;
    }
    .ellipsis .overlay {
        position: absolute;
        top: 0;
        left: 50%;
        width: 100%;
        height: 100%;
        overflow: hidden;
    
        /**
        overflow: visible;
        left: 0;
        background: rgba(0,0,0,.5);
        /**/
    }
    .ellipsis .overlay:before {
        content: "";
        display: block;
        float: left;
        width: 50%;
        height: 100%;
    
        /**
        background: lightgreen;
        /**/
    }
    .ellipsis .placeholder {
        float: left;
        width: 50%;
        height: 40px;/* h*n */
    
        /**
        background: lightblue;
        /**/
    }
    .ellipsis .more {
        position: relative;
        top: -20px;/* -h */
        left: -50px;/* -w */
        float: left;
        color: #000;
        width: 50px;/* width of the .more w */
        height: 20px;/* h */
        font-size: 14px;
    
        /**
        top: 0;
        left: 0;
        background: orange;
        /**/
    }
    text text text text text text text text text text text text text text text text text text text text text
    ...more

提交回复
热议问题