文本超长打点

对于单行文本,使用单行省略:

{
    width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

而对于多行文本的超长省略,使用 -webkit-line-clamp 相关属性,兼容性也已经非常好了:

{
    width: 200px;
    overflow : hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

案例

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 200px;
      height: 48px;
      margin: 10px;
      background-color: rgb(216, 210, 210);
    }

    .singleOver {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .multiple {
      overflow : hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  </style>
</head>

<body>
  <div class="box singleOver">
    七月的风懒懒的
    连云都变热热的
    不久后天闷闷的
    一阵云后雨下过
  </div>
  <div class="box multiple">
    七月的风懒懒的
    连云都变热热的
    不久后天闷闷的
    一阵云后雨下过
  </div>
</body>

</html>

最后修改:2021 年 09 月 11 日 01 : 16 PM
如果觉得我的文章对你有用,请随意赞赏