With CSS, use “…” for overflowed block of multi-lines

后端 未结 16 2575
情话喂你
情话喂你 2020-11-22 07:15

with

overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

\"...\" will be shown in the end of the line if overflowed. However, t

16条回答
  •  天涯浪人
    2020-11-22 07:34

    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

提交回复
热议问题