【发布时间】:2018-02-03 11:32:34
【问题描述】:
我目前正在尝试解决 display: flex 和 Internet Explorer 11 的问题。我有一个固定宽度的表格,其中有一个带有 display: flex 的 div。这会导致表格在 IE11 中被拉伸。我尝试使用 flex-wrap 属性,它根本不会改变 IE 中的行为,但也会破坏 chrome 中的布局。当您在 IE11 和 Chrome(或基本上任何其他浏览器)中打开它时,我将代码分解为下面的 sn-p,它显示了问题。有谁知道如何在 IE11 中实现 Chrome 的正确行为?
(初始片段)
table {
width: 200px;
border: 1px solid #000;
}
.flex {
display:flex;
}
.icon:before {
content: "✆";
}
<table>
<tr>
<td>
<div class="flex">
<span class="icon"></span>
<span class="content">Lorem Ipsum dolor sit amet Lorem Ipsum dolor and so on ...</span>
</div>
</td>
</tr>
</table>
编辑 1: 在尝试了 Paulie_D 和 LGSon 的答案后,它会导致表格预定义列宽,而不是等待对于实际的内容宽度,这会导致一些文本溢出。我更新了下面的片段以显示这一点。能够用 LGSons 的答案重现它,目前正在深入挖掘 Paulie_D 的答案。
table {
width:200px;
border: 1px solid #000;
table-layout: fixed;
}
.flex {
display:flex;
}
.icon:before {
content: "✆";
}
<table>
<tr>
<td>
<div class="flex">
<span class="icon"></span>
<span class="content">Lorem Ipsum dolor sit amet Lorem Ipsum dolor and so on ...</span>
</div>
</td>
<td>
<span class="content">LongWordWithoutWhitespace</span>
</td>
</tr>
</table>
编辑 2: 我能够重现 Paulie_D 解决方案的问题,请查看下面的 sn-p:
table {
width: 90%;
border: 1px solid #000;
table-layout: fixed;
}
.flex {
display:flex;
}
.icon:before {
content: "✆";
}
.content {
flex-grow: 1;
flex-shrink: 0;
flex-basis: 0;
}
<table>
<tr>
<td>
<div class="flex">
<span class="icon"></span>
<span class="content">Lorem Ipsum dolor sit amet Lorem Ipsum</span>
</div>
</td>
<td>
<div class="flex">
<span>Content here</span>
</div>
</td>
<td>
<div class="flex">
<span>and_some_long_content_here</span>
</div>
</td>
</tr>
</table>
【问题讨论】:
-
愚蠢的问题,但我需要一个前缀或类似的东西吗?
-
IE11的flexbox有很多问题。在此处查看已知问题标签:caniuse.com/#search=flexbox
-
IE11不需要前缀,IE10需要
-ms-
标签: html css internet-explorer flexbox