【问题标题】:flex-shrink won't shrink item in IE 10/11 and causes parent to be wider than parentflex-shrink 不会在 IE 10/11 中缩小项目并导致父项比父项更宽
【发布时间】:2017-08-12 08:40:26
【问题描述】:

我的布局由一行三列组成。

左右应与其内容一样宽。宽度的其余部分应由标题列占据。所有列的总宽度不得大于父列。

所有列都应该只有一行内容,没有换行符。

如果标题列的内容不符合约束条件,则应在末尾添加省略号。

所有这些都适用于 Chrome 和 Edge,但 IE 拒绝缩小标题列,以便这些列适合其父级的宽度。

html,
body {
  width: 100%;
  margin: 0;
}

.row {
  display: -ms-flexbox;
  display: flex;
  /* https://css-tricks.com/snippets/css/a-guide-to-flexbox/ */
  width: 200px;
}

[class*='cell-'] {
  -ms-flex: 0 0 auto;
      flex: 0 0 auto;
  /* https://css-tricks.com/flexbox-truncated-text/ */
  min-width: 0;
}

.cell-left {
  background: red;
}

.cell-title {
  white-space: nowrap;
  -ms-flex: 0 1 auto;
      flex: 0 1 auto;
}

.hover {
  overflow-x: hidden;
  text-overflow: ellipsis;
  position: relative;
  padding-right: 1em;
}

.chevron {
  position: absolute;
  right: 0;
}

.hover:hover {
  background: green;
}

.cell-right {
  background: yellow;
  margin-left: auto;
}
<div class="row">
  <div class="cell-left">Left</div>
  <div class="cell-title">
    <div class="hover">Pellentesque habitant morbi tristique senectus et netus et malesuada<span class="chevron">^</span></div>
  </div>
  <div class="cell-right">Right</div>
</div>

【问题讨论】:

    标签: css flexbox internet-explorer-11 internet-explorer-10


    【解决方案1】:

    IE 10/11 需要在中间项上指定宽度。对您的代码进行此调整

    .row {
      display: flex;
      width: 200px;
    }
    
    .cell-title {
      width: 100%;
      min-width: 0;
      display: flex;
    }
    
    .hover {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    
    .cell-title::after {
      content: '^';
      padding-left: 5px;
      margin-right: auto;
    }
    
    .hover:hover { background: green; }
    .cell-left   { background: red; }
    .cell-right  { background: yellow; }
    html, body   { margin: 0; }
    <div class="row">
      <div class="cell-left">Left</div>
      <div class="cell-title">
        <div class="hover">Pellentesque habitant morbi tristique senectus et netus et malesuada</div>
      </div>
      <div class="cell-right">Right</div>
    </div>

    jsFiddle demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 2019-08-02
      • 2016-08-03
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多