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

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

    I've found this css (scss) solution that works quite well. On webkit browsers it shows the ellipsis and on other browsers it just truncates the text. Which is fine for my intended use.

    $font-size: 26px;
    $line-height: 1.4;
    $lines-to-show: 3;
    
    h2 {
      display: block; /* Fallback for non-webkit */
      display: -webkit-box;
      max-width: 400px;
      height: $font-size*$line-height*$lines-to-show; /* Fallback for non-webkit */
      margin: 0 auto;
      font-size: $font-size;
      line-height: $line-height;
      -webkit-line-clamp: $lines-to-show;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    

    An example by the creator: http://codepen.io/martinwolf/pen/qlFdp

提交回复
热议问题