gpt4 book ai didi

html - Flexbox、flex-direction : column, 图像和 IE11 错误。这能解决吗?

转载 作者:太空狗 更新时间:2023-10-29 12:31:56 25 4
gpt4 key购买 nike

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

每个<li>包含一个 anchor display: flex列,以正确对齐其中的元素,包括主图像容器和图像。在每个浏览器中,包括 IE10,这绝对没问题,没有问题。然而,在 IE11 中,这就是问题的开始。

IE11 将图像容器高度计算为源图像的实际高度,而不是渲染时图像的高度。这最终呈现了 <li>比应有的高度高很多。

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

demonstration

布局在 IE11 中的外观:

demonstration

查看 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>

最佳答案

这似乎可以通过在 .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>

关于html - Flexbox、flex-direction : column, 图像和 IE11 错误。这能解决吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38441094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com