关于css:flex布局下子元素设置超出隐藏显示省略号失败解决方案

4次阅读

共计 726 个字符,预计需要花费 2 分钟才能阅读完成。

给父级元素加 width: 0;

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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    #box {
      width: 300px;
      display: flex;
      justify-content: space-between;
      /* align-items: center; */
      border: 1px solid red;
      box-sizing: border-box;
      line-height: 50px;
    }
    .left{
      background-color: yellowgreen;
      flex: 1;
      // 父元素设置宽度为 0
      width: 0;
    }
    .text {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      height: 50px;
    }

    .right {
      width: 100px;
      /* height: 50px; */
      background-color: #e4b9b9;
      /* border-radius: 10px; */
    }
  </style>
</head>

<body>
  <div id="box">
    <div class="left">
      <p class="text"> 内容内容内容内容内容内容内容内内容内容内容内容内容内容内容内容内容内容内容内容容内容内容内容内容 </p>
    </div>
    <div class="right"> 我在左边 </div>
  </div>
</body>

</html>
正文完
 0