gpt4 book ai didi

html - 结合 flex 和绝对定位时的混淆

转载 作者:行者123 更新时间:2023-12-04 12:11:17 27 4
gpt4 key购买 nike

我有一个应用程序,它本质上是一个页眉、主要内容和一个始终可见的页脚。页脚可以改变大小,我想在页脚上方的主内容面板上放置一些工具。主要布局是用 flex 完成的,我阅读文档的理解是绝对定位通过相对于最近的后代定位来与 flex 布局相结合,但这似乎不是我的经验。希望有人可以帮助我。

在下面的代码示例中,我希望看到位于页脚上方的“底部”div,但它实际上位于窗口的底部。
这是 jsfiddle 链接:http://jsfiddle.net/L809zbey/

HTML:

<div class="flex">
<div class="header">Sweet header</div>
<div class="content">Main content
<div class="bottom">
This guy should be fixed above the footer.
</div>
</div>

<div class="footer">Equally sweet footer</div>
</div>

CSS:
.flex{
border: 1px solid #ddd;
font: 14px Arial;
display: flex;
flex-direction: column;
}

.header{
background : #007AA2;
flex: 0 0 auto;
}

.content{
background : #FFF;
flex: 1 1 auto;
height: 200px;
}

.footer{
background : #7FCADE;
flex: 0 0 auto;
}

.bottom {
position: absolute;
bottom: 20px;
}

最佳答案

尝试添加 position:relative;给您的 .flex类(class)。 .bottom元素当前是相对于正文的,因此为什么它被卡在页面底部。

关于html - 结合 flex 和绝对定位时的混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53751065/

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