【问题标题】:Flexbox, flex-direction: column, image and IE11 bug. Can this be solved?Flexbox、flex-direction:列、图像和 IE11 错误。这可以解决吗?
【发布时间】:2016-11-21 07:39:47
【问题描述】:

我有一个包含<ul>display: flex 水平。每个<li> 的宽度为 25%,display: flex 的高度也相同。

每个<li> 都包含一个display: flex 列的锚点,以正确对齐其中的元素,包括主图像容器和图像。在包括 IE10 在内的所有浏览器中,这都很好,没有问题。然而,在 IE11 中,问题就从这里开始了。

IE11 将图像容器高度计算为源图像的实际高度,而不是渲染时图像的高度。这最终会渲染<li> 比它应该的高得多。

布局在每个自尊的浏览器中的外观:

布局在 IE11 中的外观:

查看live example

我知道这可以通过明确定义图像高度来解决,但我不想这样做。我也可以用 JS 来解决它,但同样,我不应该这样做。我错过了什么吗,因为它似乎没有在Flexbugs 上列出。

* {
      box-sizing: border-box;
    }

    img {
      display: block;
      width: 100%;
    }

    .promotions-list {
      background-color: #eaeaea;
      display: -webkit-box;
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex;
      -webkit-flex-wrap: wrap;
          -ms-flex-wrap: wrap;
              flex-wrap: wrap;
      padding: .5rem 1rem;
      width: 960px;
    }
    .promotions-list__item {
      display: -webkit-box;
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex;
      padding: 1rem;
      width: 25%;
    }
    .promotions-list__link {
      background-color: white;
      display: -webkit-box;
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-flex: 1;
      -webkit-flex: 1 1 auto;
          -ms-flex: 1 1 auto;
              flex: 1 1 auto;
      -webkit-box-orient: vertical;
      -webkit-box-direction: normal;
      -webkit-flex-direction: column;
          -ms-flex-direction: column;
              flex-direction: column;
      overflow: hidden;
      padding: 1em;
      position: relative;
      width: 100%;
    }
    .promotions-list .image-container {
      display: block;
      height: auto;
    }
    .promotions-list .image-container img {
      display: block;
      margin: 0 auto;
      max-width: 40%;
    }
<ul class="promotions-list">
        <li class="promotions-list__item has-image">
            <a href="/promotion/358/the-new-l5000-mono-laser-range-from-brother" class="promotions-list__link" title="Link to The NEW L5000 Mono Laser Range from Brother details">
                <span class="promotions-list__item__header">
                    <span class="image-container">
                        <img src="//cdn.2020prosoftware.com/installations/1/promotions/358/original/NewModel2016.png">
                    </span>

                <span class="list__item__title">The NEW L5000 Mono Laser Range from Brother</span>
                </span>

                <span class="promotions-list__item__body">
                    <span class="description">The NEW standard in reliability! Introducing new, improved printers from Brother, the market leader…</span>
                </span>
            </a>
        </li>
    </ul>

【问题讨论】:

  • 一个非常相似的问题在您的提问前几个小时发布了。我的回答也可能适用于这里:stackoverflow.com/q/38431915/3597276
  • @Michael_B 不幸的是,我无法让您的示例在我的布局上起作用。

标签: html css flexbox internet-explorer-11


【解决方案1】:

这似乎可以通过在.promotions-list__item__header 上设置flex: 0 0 auto 来解决。

* {
  box-sizing: border-box;
}

img {
  display: block;
  width: 100%;
}

.promotions-list {
  background-color: #eaeaea;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  padding: .5rem 1rem;
  width: 960px;
}
.promotions-list__item {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  padding: 1rem;
  width: 25%;
}
.promotions-list__link {
  background-color: white;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
  overflow: hidden;
  padding: 1em;
  position: relative;
  width: 100%;
}
.promotions-list .image-container {
  display: block;
  height: auto;
}
.promotions-list .image-container img {
  display: block;
  margin: 0 auto;
  max-width: 40%;
}

/* Added */
.promotions-list__item__header {
  flex: 0 0 auto;
}
<ul class="promotions-list">
    <li class="promotions-list__item has-image">
        <a href="/promotion/358/the-new-l5000-mono-laser-range-from-brother" class="promotions-list__link" title="Link to The NEW L5000 Mono Laser Range from Brother details">
            <span class="promotions-list__item__header">
                <span class="image-container">
                    <img src="//cdn.2020prosoftware.com/installations/1/promotions/358/original/NewModel2016.png">
                </span>

                <span class="list__item__title">The NEW L5000 Mono Laser Range from Brother</span>
            </span>

            <span class="promotions-list__item__body">
                <span class="description">The NEW standard in reliability! Introducing new, improved printers from Brother, the market leader…</span>
            </span>
        </a>
    </li>
</ul>

【讨论】:

  • 你这个小英雄。我可以发誓我尝试了所有的迭代,但显然不是。谢谢!
猜你喜欢
  • 2019-02-25
  • 2017-08-03
  • 2018-07-21
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 2019-09-23
  • 1970-01-01
相关资源
最近更新 更多