首页 > 解决方案 > 即使使用旧前缀,Flex 属性在 IE 10 中也不起作用

问题描述

我创建了一个英雄,文本位于图像的左侧,使用 flexbox 自动将文本定位在 div 的中心,相对于图像。

我使用了旧的和新的 IE 前缀来使它能够在最新版本的 IE 上运行,但它似乎不适用于 IE 10。文本 div 似乎延伸到整个列的宽度,并且在后面右边的图像。关于为什么会发生这种情况的任何想法?

代码:

.hero {
  background-color: #3c763d;
  text-align: center;
}

.flex {
  display: -ms-flexbox;
  display: -moz-flex;
  display: -webkit-box;
  display: -moz-box;
  display: flex;
  -ms-flex-wrap: wrap;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  flex-direction: row;
}

.d-flex {
  -ms-flex-align: center!important;
  -webkit-box-align: center!important;
  align-items: center!important;
  display: -ms-flexbox!important;
  display: -webkit-box;
  display: flex;
  margin-top: 0;
  margin-left: auto;
  margin-right: auto;
  -moz-flex: 1 1 15em;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 15em;
  flex: 1 1 15em;
}

.img-responsive {
  display: block;
  max-width: 100%;
  height: auto;
}
<section class="section hero">
  <div class="container">
    <div class="row flex">
      <div class="col-xs-12 col-md-6 d-flex">
        <div>
          <h2>Headline</h2>
          <p>Paragraph text</p>
        </div>
      </div>
      <div class="col-xs-12 col-md-6">
        <div>
          <img class="img-responsive" src="http://pngplay.com/wp-content/uploads/1/Laptop-PNG-Image.png">
        </div>
      </div>
    </div>
  </div>
</section>

标签: csstwitter-bootstrapflexboxinternet-explorer-10

解决方案


Can I Use说明 IE10 仅支持2012的 flexbox 语法。(它还指出,由于大量已知错误,支持被认为是部分的。)

对语法文档进行快速扫描表明它align-items不存在,而可能是flex-item-align. 此外,您的示例似乎不包含flex-direction.

3 或 4 年前曾尝试在大型 Web 应用程序中使用 flex,但最终我们只是为所有版本的 IE 使用了 Javascript 变通方法。


推荐阅读