一路繁花似锦绣前程
失败的越多,成功才越有价值

导航

 
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>flex布局处理文本溢出</title>
  <style>
  .container {
    display: flex;
  }

  .left, .right {
    flex: 1;
  }

  .right {
    /* right设置了flex后,也要设置width: 0;。
      不然会被child撑开,而导致文本无法超出隐藏 */
    width: 0;
    background: red;
  }

  .text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  </style>
</head>
<body>
<div class="container">
  <div class="left text">这是一段中文这是一段中文这是一段中文这是一段中文这是一段中文这是一段中文</div>
  <div class="right">
    <div class="child text">这是一段中文这是一段中文这是一段中文这是一段中文这是一段中文这是一段中文</div>
  </div>
</div>
</body>
</html>
posted on 2022-11-22 12:23  一路繁花似锦绣前程  阅读(332)  评论(0编辑  收藏  举报