【问题标题】:IE 10 flex box and text truncateIE 10 弹性框和文本截断
【发布时间】:2018-02-07 00:05:36
【问题描述】:

.wrapper {
  background: tomato;
  width: 100px;
  display: flex;
}

.left {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.right {

}
<div class=wrapper>
  <div class="left">
    title title title title
  </div>
  <div class="right">
    123
  </div>
</div>

我有一个 DIV (wrapper),里面有 2 个 DIV:leftright

wrapper 的宽度是已知的。如果不适合,我想截断left DIV 中的文本。 right 中的文本应始终可见。我在这里尝试了几种技术,但唯一有效的是基于 flex box。不幸的是,它不适用于 IE10。我使用了-ms- 前缀,但没有成功。

有什么办法让它在 IE10 上运行?

【问题讨论】:

    标签: html css flexbox internet-explorer-10


    【解决方案1】:

    我自己无法在 IE10 上对此进行测试,但由于其 -ms-flex 默认为 0 0 auto,因此您需要将 -ms-flex: 0 1 auto 添加到 left,因此它可以缩小。

    IE11 和其他浏览器的默认值为0 1 auto,它们按原样工作。

    Fiddle demo

    堆栈sn-p

    .wrapper {
      background: tomato;
      width: 100px;
      display: -ms-flexbox;                     /*  IE10  */
      display: flex;
    }
    
    .left {
      -ms-flex: 0 1 auto;                       /*  IE10  */
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    
    .right {
    
    }
    <div class=wrapper>
      <div class="left">
        title title title title
      </div>
      <div class="right">
        123
      </div>
    </div>

    【讨论】:

    • 与表格解决方案中的相同问题:如果wrapper 很宽,则123 文本将位于右侧。这是因为flex: 1 in left
    • @user3452568 更新了我的答案,这样它就可以正常工作了
    【解决方案2】:

    这是一个不使用 flexbox 而是使用 display:table 的想法:

    .wrapper {
      background: tomato;
      width: 100px;
      display: table;
    }
    
    .left {
      display: table-cell;
      position: relative;
      width: 100%;
    }
    
    .left span {
      position: absolute;
      top:0;
      left:0;
      width: 100%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    
    .right {
      display: table-cell;
    }
    <div class=wrapper>
      <div class="left">
        <span>
        title title title title title title
       </span>
      </div>
      <div class="right">
        123
      </div>
    </div>

    【讨论】:

    • 谢谢!它用省略号来解决问题,但是当我的wrapper 更宽时,例如200px,文字123 到右侧:( 我想把它放在left DIV 旁边。
    • @user3452568 啊,是因为宽度100%我应用到第一个...我会想一个技巧
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多