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

后端 未结 16 2356
情话喂你
情话喂你 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:28

    thanks @balpha and @Kevin, I combine two method together.

    no js needed in this method.

    you can use background-image and no gradient needed to hide dots.

    the innerHTML of .ellipsis-placeholder is not necessary, I use .ellipsis-placeholder to keep the same width and height with .ellipsis-more. You could use display: inline-block instead.

    .ellipsis {
        overflow: hidden;
        position: relative;
    }
    .ellipsis-more-top {/*push down .ellipsis-more*/
        content: "";
        float: left;
        width: 5px;
    }
    .ellipsis-text-container {
        float: right;
        width: 100%;
        margin-left: -5px;
    }
    .ellipsis-more-container {
        float: right;
        position: relative;
        left: 100%;
        width: 5px;
        margin-left: -5px;
        border-right: solid 5px transparent;
        white-space: nowrap;
    }
    .ellipsis-placeholder {/*keep text around ,keep it transparent ,keep same width and height as .ellipsis-more*/
        float: right;
        clear: right;
        color: transparent;
    }
    .ellipsis-placeholder-top {/*push down .ellipsis-placeholder*/
        float: right;
        width: 0;
    }
    .ellipsis-more {/*ellipsis things here*/
        float: right;
    }
    .ellipsis-height {/*the total height*/
        height: 3.6em;
    }
    .ellipsis-line-height {/*the line-height*/
        line-height: 1.2;
    }
    .ellipsis-margin-top {/*one line height*/
        margin-top: -1.2em;
    }
    .ellipsis-text {
        word-break: break-all;
    }
    ...more
    text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
    ...more

    jsfiddler

提交回复
热议问题