简体   繁体   English

flexbox文本从Internet Explorer 11中的div中溢出

[英]flexbox text spilling out of div in Internet Explorer 11

I have created a simple setup with some wrappers using flexbox to control spacing on a page. 我创建了一个简单的设置,其中包含一些使用flexbox来控制页面间距的包装器。 It has two headers which have fixed positions, a footer and some space in between that always fills up the rest of the screen vertically regardless of how much content is actually on the page. 它具有两个具有固定位置的页眉,页脚和之间的一些空间,无论页面上实际有多少内容,它们始终会垂直填充屏幕的其余部分。

Now I wanted to add a div in between the #content_wrapper and the #header_wrapper which I want to resize depending on its content and the browser width. 现在,我想在#content_wrapper和#header_wrapper之间添加一个div,我想根据其内容和浏览器宽度来调整大小。 To this end I added the #sub_header_wrapper div. 为此,我添加了#sub_header_wrapper div。

This all works as expected in Firefox, but in Internet Explorer the text in the #sub_header_wrapper div spills out and starts overlapping the #content_wrapper text. 所有这些都可以在Firefox中正常运行,但是在Internet Explorer中,#sub_header_wrapper div中的文本会溢出并开始与#content_wrapper文本重叠。 Why is this happening and how can this be fixed? 为什么会发生这种情况,如何解决?

jsfiddle: https://jsfiddle.net/mevn8bvL/21/ jsfiddle: https ://jsfiddle.net/mevn8bvL/21/

 h1, h2, h3, h4, h5, h6, p { margin: 0; padding: 0; } /* needed to reset CSS so you dont get extra unneeded whitespace */ html, body { margin: 0; /* required to avoid scroll bars due to min-height 100vh */ } #outer_wrapper { margin: 0; height: 0; /* required by IE to make flex-grow work */ min-height: 100vh; background-color: pink; display: flex; flex-direction: column; } /* flex-grow is 99 to offset the variable nature of the sub header containers. */ #content_wrapper { background-color: green; flex-grow: 99; /* this is what makes the div expand even when there's no content. */ } #article_list { background-color: red; } #header_wrapper { position: fixed; width: 100%; z-index: 199; box-shadow: 0px 10px 5px rgba(0, 0, 0, 0.2); } #header_top_wrapper, #header_bottom_wrapper { height: 70px; min-height: 70px; /* min-height required to enforce the height */ } #sub_header_wrapper { background-color: rgb(150, 150, 255); margin-top: 140px; flex: 1 1 auto; } #header_top_wrapper { background-color: yellow; } #header_bottom_wrapper { background-color: orange; } #footer_wrapper { height: 100px; min-height: 100px; background-color: blue; } 
 <div id="outer_wrapper"> <div id="header_wrapper"> <div id="header_top_wrapper"> header top </div> <div id="header_bottom_wrapper"> header bottom </div> </div> <div id="sub_header_wrapper"> sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. sub header with informational text. </div> <div id="content_wrapper"> <div id="article_list"> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> </div> </div> <div id="footer_wrapper"> footer </div> </div> 

This appears to be the source of the problem: 这似乎是问题的根源:

#sub_header_wrapper {
  flex: 1 1 auto;
}

This rule breaks down to: 该规则分解为:

  • flex-grow: 1
  • flex-shrink: 1
  • flex-basis: auto

In Chrome and Firefox, the height of the item is the height of the content ( flex-basis: auto ). 在Chrome和Firefox中,项目的高度是内容的高度( flex-basis: auto )。 This height is maintained even though the item has flex-shrink: 1 . 即使项目具有flex-shrink: 1也将保持此高度。 Basically, the item doesn't shrink below its content height. 基本上,项目不会收缩到其内容高度以下。

Not so in IE11. 在IE11中不是这样。 The flex-shrink rule enables the item to shrink below its content height. flex-shrink规则使项目可以收缩到其内容高度以下。

The solution is to disable flex-shrink . 解决方案是禁用flex-shrink This fixes the problem in IE11 while not changing anything in other browsers. 这样可以解决IE11中的问题,而无需在其他浏览器中进行任何更改。

Make this adjustment to your code: 对您的代码进行此调整:

#sub_header_wrapper {
  flex: 1 0 auto;
}

revised demo 修改后的演示

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

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