gpt4 book ai didi

css - 最小高度不能正常工作?

转载 作者:行者123 更新时间:2023-12-02 20:41:21 25 4
gpt4 key购买 nike

我正在尝试创建一个最小高度为 100% 的 DIV,这在 FireFox/IE 中不起作用。它仅在使用“高度”属性时有效。

Chrome 运行正常。

<style>
.page{
min-height:100%;
border:1px solid black;
}
</style>
<html>
<div class="page">
With firefox / IE, this div is not stretching to take 100% of the total page height.
</div>
</html>

更新:

我知道我需要定义 body/html 的高度。这就说得通了。但是即使有了这个解决方案,我仍然不能对子 div 使用最小高度。请参见下面的示例。子 div 没有占用父 div 的 33%。 (在 FIREFOX 和 IE 中)

<style>
.page{
min-height:100%;
border:1px solid black;
}

html,
body {
height: 100%;
}

.child{
min-height:33%;
border:1px solid black;
display:flex;
}

</style>
<html>
<div class="page">
Parent div
<div class="child">
With firefox / IE, this CHILD div is not stretching to take 33% of the container.
</div>
</div>
</html>

最佳答案

你还需要给 htmlbody 一个高度

html, body {
height: 100%;
}

更新 1,问题编辑后

有了新标记,.page 也需要 height: 100%

html,
body {
height: 100%;
}

.page {
height: 100%;
border: 1px solid black;
}

.child {
min-height: 100%;
border: 1px solid red;
display: flex;
}
<div class="page">
<div class="child">
With firefox / IE, this CHILD div is not stretching to take 100% of the container.
</div>
</div>


更新 2,基于评论

改用 Flexbox 和视口(viewport)单元 vh,效果会更好

body {
display: flex; /* IE need this for its 'min-height' bug */
}

.page {
min-height: 100vh;
border: 1px solid black;
display: flex;
flex-direction: column;
}

.child {
flex-grow: 1;
border: 1px solid red;
}
<div class="page">
<div class="child">

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

</div>
</div>

这也适用于 min-height: 33%

body {
display: flex; /* IE need this for its 'min-height' bug */
}

.page {
min-height: 100vh;
border: 1px solid black;
display: flex;
flex-direction: column;
}

.child {
min-height: 33%;
border: 1px solid red;
}
<div class="page">
<div class="child">

With firefox / IE, this CHILD div is not stretching to take 100% of the container.<br>

</div>
</div>

关于css - 最小高度不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46023951/

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