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

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

    Here is the closest solution I could get using just css.

    HTML

    ... Hello this is Mr_Green from Stackoverflow. I love CSS. I live in CSS and I will never leave working on CSS even my work is on other technologies.

    CSS

    div {
        height: 3em;
        line-height: 1.5em;
        width: 80%;
        border: 1px solid green;
        overflow: hidden;
        position: relative;
    }
    div:after {
        content:". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . . . . . . . . . . . . . . .";
        background-color: white;
        color: white;
        display: inline;
        position: relative;
        box-shadow: 8px 1px 1px white;
        z-index: 1;
    }
    span {
        position: absolute;
        bottom: 0px;
        right: 0px;
        background-color: white;
    }
    

    Working Fiddle (resize the window to check)

    Link to my blog for explanation

    Updated Fiddle

    I hope now some css expert would have got idea on how to make it perfect. :)

提交回复
热议问题