简体   繁体   English

Internet Explorer在flexbox中拉伸图像

[英]Internet Explorer stretches image in flexbox

I want to create full height section with 2 sections. 我想用2个部分创建全高度部分。

In the first one is just text and in the second one a image. 第一个是文本,第二个是图像。

I'm using flexbox for this and it works fine in Chrome, FF, Edge but not in IE. 我正在使用flexbox,它在Chrome,FF,Edge中运行良好,但在IE中却不行。

 #super { height: 100vh; } #super #el-1 { display: flex; flex-flow: column; height: 100%; } #super #el-1 .above, #super #el-1 .below { display: flex; flex-flow: column; align-items: center; } #super #el-1 .above { text-align: center; padding: 100px 0; } #super #el-1 .below img { width: 60%; max-width: 100%; height: auto; vertical-align: middle; } 
 <div id="super"> <div id="el-1"> <div class="above"> <h1>Some crazy text here!!!</h1> <h2>Wow a second line - amazing :o</h2> </div> <div class="below"> <img src="http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg"> </div> </div> </div> 

https://jsfiddle.net/0cw3epzv/ https://jsfiddle.net/0cw3epzv/

IE is notorious for having many flexbugs . IE因许多弹片而臭名昭着。 It's reliable for very simple flex layouts. 它对于非常简单的flex布局是可靠的。 But with even the slightest bit of complexity, IE requires "special attention" (ie, ugly hacks). 但即使是最轻微的复杂性,IE也需要“特别关注”(即丑陋的黑客攻击)。

In this particular case, it appears IE requires a height limitation on the parent of the image: 在这种特殊情况下,IE似乎需要对图像的父级进行高度限制:

Instead of this: 而不是这个:

.below { }

img {
    width: 60%;
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

Try this: 尝试这个:

.below {
    flex: 0 0 200px; /* flex-basis: 200px (demo value only) */
}

img {
    height: 100%;
    /* flex: 0 0 100%;  <--- this should work also, but it doesn't */
}

revised fiddle 修改过的小提琴

To avoid that for browser compatibility you can try this option. 为避免浏览器兼容性,您可以尝试此选项。 What i did was to remove flex from the ".below" class and centered the img element in it. 我所做的是从“.below”类中删除flex并将img元素置于其中。 Hope it helps 希望能帮助到你

#super {

  height: 100vh;

  #el-1 {

    display: flex;
    flex-flow: column;
    height: 100%;

    .above {
      display: flex;
      flex-flow: column;
      align-items: center;
    }
    .below {
      text-align: center;
    }

    .above {
      text-align: center;
      padding: 100px 0;
    }

    .below {

      img {
        width: 60%;
        max-width: 100%;
        height: auto;
        vertical-align: middle;
      }

    }

  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM