gpt4 book ai didi

html - Flexbox 在 Internet Explorer 11 中不工作

转载 作者:技术小花猫 更新时间:2023-10-29 11:50:03 25 4
gpt4 key购买 nike

这段代码在 Firefox、Chrome 和 Edge 中运行良好,但显然由于 flex 模型,它在 IE11 中无法正常运行。我该如何解决?

这是它在 Firefox 中的样子

enter image description here

这是它在 IE11 中的样子

enter image description here

body * {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
min-height: 100%;
display: flex;
flex-flow: column;
margin: 0;
}
main {
flex: 1;
display: flex;
}
header,
footer {
background: #7092BF;
border: solid;
width: 100%;
}
section {
border: solid;
background: #9AD9EA;
flex: 1
}
aside {
border: solid;
width: 150px;
background: #3E48CC
}
<header>
<p>header
</header>
<main>
<aside>
<p>aside
<p>aside
</aside>
<section>
<p>content
<p>content
<p>content
<p>content
</section>
</main>
<footer>
<p>footer
<p>footer
</footer>

最佳答案

根据 Flexbugs :

In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.

这里有一些解决方法:

<强>1。始终填充视口(viewport) + 可滚动 <aside><section> :

html {
height: 100%;
}

body {
display: flex;
flex-direction: column;
height: 100%;
margin: 0;
}

header,
footer {
background: #7092bf;
}

main {
min-height: 0; /* added 2021*/
flex: 1;
display: flex;
}

aside, section {
overflow: auto;
}

aside {
flex: 0 0 150px;
background: #3e48cc;
}

section {
flex: 1;
background: #9ad9ea;
}
<header>
<p>header</p>
</header>

<main>
<aside>
<p>aside</p>
</aside>
<section>
<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>
</section>
</main>

<footer>
<p>footer</p>
</footer>

<强>2。初始填充视口(viewport) + 使用更多内容的正常页面滚动:

html {
height: 100%;
}

body {
display: flex;
flex-direction: column;
height: 100%;
margin: 0;
}

header,
footer {
background: #7092bf;
}

main {
flex: 1 0 auto;
display: flex;
}

aside {
flex: 0 0 150px;
background: #3e48cc;
}

section {
flex: 1;
background: #9ad9ea;
}
<header>
<p>header</p>
</header>

<main>
<aside>
<p>aside</p>
</aside>
<section>
<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>
</section>
</main>

<footer>
<p>footer</p>
</footer>

关于html - Flexbox 在 Internet Explorer 11 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37905749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com