【发布时间】:2017-03-15 19:03:38
【问题描述】:
当用户向下滚动时,我有一个固定的 div 会覆盖页面底部的内容。这特别影响移动设备。我在这里重现了这个问题:http://codepen.io/bkuhl/pen/LWjXdx
这是该帖子的代码:
<div class="main-content">
Test Content
<div class="content-suffix">
Copyright
</div>
</div>
<div class="fixed-bottom-bar">
I'm covering up the Copyright text
</div>
和 CSS:
.main-content {
width: 100%;
min-height: 400px;
background-color: darkgrey;
}
.content-suffix {
padding-top: 350px;
}
.fixed-bottom-bar {
position: fixed;
bottom: 0;
right: 0;
padding: 1em;
width: 100%;
background-color: blue;
}
我考虑过的一种方法是在内容后缀中添加[padding|margin]-bottom,但在这种情况下,我在固定元素上的内容长度可变。
如何确保“版权”文本不被固定元素覆盖,记住 fixed-bottom-bar 的文本长度可变?
【问题讨论】:
-
在 content-suffix 上添加一个 margin-bottom
-
如果您的页脚高度是动态的,您可以尝试使用 jquery 在运行时获取高度,然后也使用 jquery 应用 css
-
您可以通过使用 100vh 高的列 flex 布局并将内容区域设置为
flex-grow: 1和overflow-y: scroll来拉出一个假的固定页脚,为页脚留出可变高度的空间。像这样的工作? codepen.io/mcoker/pen/JWyeqW