IE11 中的 Flex 项目重叠项目 [英] Flex items overlapping item in IE11

查看:22
本文介绍了IE11 中的 Flex 项目重叠项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 div:

  1. 顶部 div 包含一个长文本,占用多行
  2. lower div 有 min-heightflex-grow: 1

当我将窗口缩小到出现的滚动条时,在 chrome 中一切都显示正确.但是在 IE11 中 top div 被缩减为一行,并且它的文本在底部 div 的顶部.

我只能通过为顶部 div 的内容设置一些宽度来修复它(它适用于固定宽度或计算宽度,但不适用于百分比宽度)如何在不设置宽度或百分比宽度 (width:100%) 的情况下修复它?

body,html {高度:99%;填充:0;边距:0;}.flexcontainer {宽度:25%;显示:弹性;弹性方向:列;高度:100%;边框:1px 实心石灰;}.allspace {弹性增长:1;最小高度:300px;背景颜色:黄色;}.longtext {背景颜色:红色;}.textcontainer {边框:1px 纯品红色;/*IE 只有在指定宽度时才能正常工作.举例:width:calc(25vw - 2px);*/}

<div class="longtext">第 1 部分长名称 第 1 部分长名称 第 1 部分长名称

<div class="allspace">所有空间

jsfiddle:

IE11:

解决方案

IE11 充满了 flex 错误和与其他浏览器的不一致.

在这种情况下,问题的根源在于flex-shrink.

IE11 在应用 flex-shrink: 1(默认设置)后奇怪地呈现 flex 项目,这导致较低的项目与上面的兄弟项目重叠.其他主流浏览器不会出现此问题.

解决方案是禁用flex-shrink.它修复了 IE11 中的问题,而无需更改其他浏览器中的任何内容.

将此添加到您的代码中:

.longtext {弹性收缩:0;}

修正小提琴

<小时>

您可能还想查看:

I have two divs:

  1. top div contains a long text that takes up several lines
  2. lower div has min-height and flex-grow: 1

When I reducing the window to the scroll appeared, then in chrome everything is displayed correctly. But in IE11 top div is reduced to one line, and its text is on top of the bottom div.

I can fix it only with set some width for content of top div (it work with fixed width, or calc width, but not work with percentage width) How can I fix it without setting width or with percentage width (width:100%)?

body,
html {
  height: 99%;
  padding: 0;
  margin: 0;
}

.flexcontainer {
  width: 25%;
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid lime;
}

.allspace {
  flex-grow: 1;
  min-height: 300px;
  background-color: yellow;
}

.longtext {
  background-color: red;
}

.textcontainer {
  border: 1px solid magenta;
  /*IE work correctly only when specified width. by example: width:calc(25vw - 2px);*/
}

<div class="flexcontainer">
  <div class="longtext">
    section 1 with long name section 1 with long name section 1 with long name
  </div>
  <div class="allspace">
    all space
  </div>
</div>

jsfiddle: https://jsfiddle.net/tkuu28gs/14/

Chrome:

IE11:

解决方案

IE11 is full of flex bugs and inconsistencies with other browsers.

In this case, the source of the problem is flex-shrink.

IE11 is rendering flex items oddly after applying flex-shrink: 1 (a default setting), which causes the lower item to overlap its sibling above. This problem doesn't occur in other major browsers.

The solution is to disable flex-shrink. It fixes the problem in IE11 without changing anything in other browsers.

Add this to your code:

.longtext {
    flex-shrink: 0;
}

revised fiddle


You may also want to look into:

这篇关于IE11 中的 Flex 项目重叠项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆