twitter-bootstrap 使 flexbox 在 IE11 中工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47137289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 01:08:03  来源:igfitidea点击:

Making flexbox work in IE11

twitter-bootstrapcssflexboxinternet-explorer-11

提问by katie hudson

I know there are similar questions about, but I have tried all of the suggestions and still cant get it working. I am using Bootstrap, and I have a section that is 100vh in height. Within this section I have two rows, the second row I needed placing at the very bottom of the section, but did not want to use absolute positioning. As such, I used the flex system.

我知道有类似的问题,但我已经尝试了所有建议,但仍然无法正常工作。我正在使用 Bootstrap,我有一个高度为 100vh 的部分。在本节中,我有两行,第二行我需要放置在该节的最底部,但不想使用绝对定位。因此,我使用了 flex 系统。

My layout was like so

我的布局是这样的

.mn120 {
  min-height: 120px;
}

img {
  max-width: 40%;
}

.mh100vh {
  min-height: 900px;
}

.col-md-4 {
  margin-top: auto;
}
<section id="someSection" class="section">
  <div class="container d-flex flex-column justify-content-between fHeight mh100vh">
 <div class="row">
   <div class="col-md-8 offset-2">
  <h2 class="section-title">Header Text</h2>
  <p class="section-subtitle">
    Some Text
  </p>
   </div>
 </div>
 <div class="row d-flex fHeight">
   <div class="col-md-4">
  <img class="btmImg" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMkAAAD7CAMAAAD3qkCRAAAAMFBMVEX3+fnMzMzNzs72+PjQ0NDv8fHY2dny9PTo6enu8PDi4+Pd3t7U1NTe39/r7OzJycld9/9/AAAFnElEQVR4nO2di5arIAxFGcEXovz/317bTue205ckJ5hxZf9Au5eEQITomqPg8lFwX0fBTPRhJvowE32YiT7MRB9mog8z0YeZ6MNM9CFv0oQQ0p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PINoXXXwllgih9cRurYUwAGYWzoAeaABYs3MGF6kTGX7BwFvRnUD3VuGmetaA/A+vYxzRp2a1UYR37mA+FHfC4Z8LcORYfU3kAZsI8n87aZJ3BdbbkDS/eiv4EzoSXUjQ9E94mhfj65wacCa9vlKKIZ2639OQT7jPhdOe8oMWEclLlHi0Rz3lzckFLPnFex04L0TyVOw+Ddlq81tUXqK+vkSZpgBS8dq/cBdj5gokT9fwOsDPwRePCcOGagAbWFb/s1Ck5Y+qot7RUFd4JHIluo31HU2GZyByF3KG/sFRnS5oKw0SwRSdlBiObZKFTkGcIh9HpJrJXaep1jhE7YXulvExMMgGnw2eUH7UtN8kpyl+VJaiUmqzr9xoerryVRJlJrjCu/lMWKwUmTZjkb/veUVTA32oS0jRIz1eP9MP2L6FtMclNmodK0fHgssSNnw77aJJDF8e+YnQ8yowxfX2WeWuSc5iWXS2+8eP88cG8NtknMl6zdO/LSE9NQuqmofI8tYH27ZcQf5nkk0UcRgUj6hl+mV9OzDcma1R087BvdH/Et8OLucxdLU5fgu29aotvfB+ffWn3ZLImb1WxvYFxevgGsksaY3sDfUz34e/+2MO44Vf47/13ePQ3H6fe+79wOX8FNR/B5IQ/fzl0738BYk0ye/8FFF68AYxhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIbxV/gHsWx5jdRW/s8AAAAASUVORK5CYII=" alt="" />
   </div>
   <div class="col-md-8">
  <img class="btmImg" src="http://www.atfund.gatech.edu/sites/default/files/images/verticalplaceholderimage-440x680.png" alt="" />
   </div>
 </div>
  </div>
</section>

I made use of a lot of Bootstrap classes to help me achieve this layout. To demonstrate the issue, I have changed the height of the section to 900px rather than 100vh

我使用了很多 Bootstrap 类来帮助我实现这种布局。为了演示这个问题,我将部分的高度改为 900px 而不是 100vh

So, if you view this JSFiddlein something like chrome, you will see that the image row sits at the bottom of the section. However, if you view it in IE11, you will see that the image row does not sit at the bottom of the section.

因此,如果您以 chrome 之类的方式查看此JSFiddle,您将看到图像行位于该部分的底部。但是,如果您在 IE11 中查看它,您将看到图像行并未位于该部分的底部。

Is there any way to make this layout work within IE11?

有没有办法让这个布局在 IE11 中工作?

回答by Ason

You can do these 2 things to make it render the same cross browsers:

您可以执行以下 2 件事以使其呈现相同的跨浏览器:

  • IE has a min-heightbugwhen using flex columndirection, adding display: flexto its parent (section) solves that

  • IE also have some issues when it comes to auto margins, so instead of margin-top: autoon the .col-md-4item, use align-items: flex-endon the parent (row d-flex fHeight)

  • IE在使用 flex方向时有一个min-height错误,添加到它的父级 ( ) 解决了这个问题display: flexsection

  • IE在自动边距方面也有一些问题,因此不要margin-top: auto.col-md-4项目上使用,而是align-items: flex-end在父级 ( row d-flex fHeight) 上使用

Updated fiddle

更新的小提琴

Stack snippet

堆栈片段

.section {
  display: flex;               /*  added  */
}

.row.d-flex.fHeight {
  align-items: flex-end;       /*  added  */
}

.mn120 {
  min-height: 120px;
}

img {
  max-width: 40%;
}

.mh100vh {
  min-height: 900px;
}

/*
.col-md-4 {
  margin-top:auto;
}
*/
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>

<section id="someSection" class="section">
  <div class="container d-flex flex-column justify-content-between fHeight mh100vh">
    <div class="row">
      <div class="col-md-8 offset-2">
        <h2 class="section-title">Header Text</h2>
        <p class="section-subtitle">
          Some Text
        </p>
      </div>
    </div>
    <div class="row d-flex fHeight">
      <div class="col-md-4">
        <img class="btmImg" src="https://i.stack.imgur.com/V5BcV.png" alt="" />
      </div>
      <div class="col-md-8">
        <img class="btmImg" src="http://www.atfund.gatech.edu/sites/default/files/images/verticalplaceholderimage-440x680.png" alt="" />
      </div>
    </div>
  </div>
</section>

回答by Deepak Rajpal

I was using Bootstrap 4 class .d-flexwith min-height: 350px;which have no-spacing/height issue for container in IE11. Fixed by adding height to the flex container.

我正在使用 Bootstrap 4 类.d-flexmin-height: 350px;其中 IE11 中的容器没有间距/高度问题。通过向 flex 容器添加高度来修复。

Try adding height

尝试增加高度

height: 350px;