页脚粘贴到页面底部但重叠内容

时间:2018-03-31 17:44:16

标签: html css footer

我的页脚按照我的要求粘贴到页面底部,但只要页面上有足够的内容到达页脚,它就会覆盖所述内容。我试过使用固定和亲戚的位置,但都没有像我想的那样工作。我还尝试过StackOverFlow上提供的其他解决方案,但到目前为止还没有任何工作。这是我的代码。

P.S。我对HTML和CSS不是很有经验,所以如果我错过了一些明显的道歉,我会道歉。

    <div>
        <footer>
            <p class="footer">&#169; 2018 The Chipotle Bandits. All rights reserved.</p>
        </footer>
    </div>

.footer {
    color: white;
    text-align: center;
    font-size: 12px;
    position: absolute;
    bottom: 0;
    width: 100%;
    flex: 0 0 50px;
}

JSFIDDLE

4 个答案:

答案 0 :(得分:0)

您可以在身体上添加margin-bottom。

添加到您的CSS

body {
  margin-bottom: 30px;
}

答案 1 :(得分:0)

这是因为页脚位于绝对位置并从元素的正常流中移除。

为了达到这个目的,您可以尝试在内容中添加填充底部,基本上是在内容底部留下一些空白空间等于页脚的高度。

从你的小提琴:

git rebase -ip --onto <last_good_commit>

答案 2 :(得分:0)

您需要设置页脚的height,然后删除position: absolute,或者如果您想要固定的页脚,则可以使用position: fixed。我也删除了保证金。

此外,单独的footer元素样式和您的.footer类样式。我将课程重命名为footer-text。我也使用flex对文本进行了集中。

footer {
  /*
  position: fixed;
  bottom: 0;
  */
  background-color: green;
  width: 100%;
  height: 50px;
  flex: 0 0 50px;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.footer-text {
  color: white;
  text-align: center;
  font-size: 12px;    
}

答案 3 :(得分:0)

您需要在页脚底部精确确定页脚元素的高度,因为页脚绝对放在容器的底部。因此,可以通过在底部具有一些间隙来纠正内容重叠。更新页脚主体css,如下所示

body {
    margin: 0;
    font-family: arial;
    background-color: #363636;
    padding: 0px;
    display: flex;
    flex-direction: column;
    padding-bottom: 38px;
}

另一种情况, 如果您总是希望页脚即使在滚动即粘性页脚时也可见,您可以使用下面给出的固定位置

.footer {
    color: white;
    text-align: center;
    font-size: 12px;
    position: fixed;
    bottom: 0;
    width: 100%;
    flex: 0 0 50px;
    background-color:#363636;
    z-index: 10;
    margin: 0;
    padding: 10px 0;
}