偶尔有特殊需求,div中直接包含文本,而不嵌套其他html标签,使文本垂直居中,如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .div {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 300px;
      height: 500px;
      overflow: hidden;
      border: 1px solid black;
    }

    .div::before {
      content: attr(customText);
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  </style>
</head>
<body>
<div class="div" customText="肯定撒开了房间啦睡觉咯开发九里峰景啦上飞机了卡是否健康啦睡觉房间啊算了解放路卡视角按时计费拉屎"></div>
</body>
</html>


qngyun1029
958 声望15 粉丝