【问题标题】:Keeping footer and bottom of page保留页脚和页面底部
【发布时间】:2021-04-19 04:14:21
【问题描述】:

我有一个网页https://jiwidi.me/home/,我有一个页脚,即使我用 js 代码注入 html 代码,我也想留在页面底部。页脚在主页https://jiwidi.me/home/ 上有效,但在https://jiwidi.me/home/blog/ 上无效,例如它不在底部的地方。在博客页面中,我正在实时插入 html 代码,从而使页面的尺寸发生变化。

我当前的页脚 css 如下所示:

footer {
    clear: both;
    margin-top: -200px;
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 2.5rem;
    text-align: center;
}

页脚也应该居中。

谢谢!

【问题讨论】:

标签: javascript html css web


【解决方案1】:

你必须添加 position:relative;在你的身体元素上

body 
{
 position:relative; 
}

#photos
{
 margin-bottom:100px; 
}

【讨论】:

  • 嗨,我进行了该修复,现在我发现页脚与 html 中的前一个元素重叠。例如,在照片部分jiwidi.me/home/photos 中,页脚与包含所有图片的 div 重叠。有什么办法可以避免吗?
  • 是的,一种方法是在你的#photos 元素中添加一个 margin-bottom 我会在我的答案中添加这个,你可能需要根据你的需要调整 margin-bottom px 值。
【解决方案2】:

你可以直接使用fixed的位置

footer {
    clear: both;
    margin-top: -200px;
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 2.5rem;
    text-align: center;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 2018-09-17
    • 2014-03-07
    • 2013-07-06
    相关资源
    最近更新 更多