blog icon indicating copy to clipboard operation
blog copied to clipboard

flex布局时,实现文本超出显示省略号需要注意的点

Open wuweijia opened this issue 6 years ago • 0 comments

关键点是 class box3 这个样式属性 需要添加一个 min-width:0;

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style media="screen">
    .box {
      display: flex;
      align-items: center;
      height: 48px;
      border: 1px solid red;
    }
    .box2 {
      display:inline-block;
      width:95px;
      font-size:14px;
      line-height:20px;
      color:#606062;
    }
    .box3{
      flex:1;
      min-width: 0;
      display:flex;
      align-items:center;
      justify-content:space-between;
      height:48px;
      padding-right:8px;
    }
    .text {
      flex: 1;
      text-overflow:ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
  </style>
</head>
<body>
  <div class="box">
    <text class="box2">123</text>
    <div class="box3">
      <div class="text">这里是你想要超过长度显示省略号的一段文字</div>
      <div>右侧的文字</div>
    </div>
  </div>
</body>
</html>

wuweijia avatar Mar 14 '18 10:03 wuweijia