Flexbox,flex-direction:列,图像和IE11错误。这可以解决吗?

时间:2016-07-18 15:51:51

标签: html css flexbox internet-explorer-11

我的<ul>包含display: flex水平。每个<li>的宽度为25%,display: flex也是<li>,以使它们具有相同的高度。

每个display: flex都包含一个<li>列的锚点,用于正确对齐元素,包括主图像容器和图像。在每个浏览器中,包括IE10这绝对没问题。但是,在IE11中,问题就出现了。

IE11将图像容器高度计算为源图像的实际高度,而不是渲染时图像的高度。这最终使* { 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%; }呈现得比它应该高得多。

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

demonstration

IE11中的布局如何显示:

demonstration

查看live example

我知道这可以通过明确定义图像高度来解决,但我不想这样做。我也可以用JS解决它,但同样,我不应该这样做。我是否遗漏了这些内容,因为它似乎没有列在Flexbugs上。

&#13;
&#13;
<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>
&#13;
{{1}}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:5)

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

* {
  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>