javascript - CSS 将固定页脚对齐到主体最小高度的底部

标签 javascript jquery html css

任何人都可以建议是否有办法保持固定页脚不超过内容的最小高度? (因此,如果内容的最小高度高于浏览器窗口(视口(viewport)),则固定页脚将保持在最小高度之上,否则如果视口(viewport)更高,则页脚应固定在底部)

我想这只能使用 JS/jQuery 来实现。如果有人能告诉我如何实现这一点,我会很感激。

html, body {
   height: 100%;
   min-height: 800px;
   width: 100%;
   margin: 0;
   padding: 0;
}
header {
   width: 100%;
   height: 50px;
   background: blue;
   position: fixed;
   top: 0;
}
#content {
   width: 85%;
   margin: 0 auto;
   padding: 50px 0;
}
footer {
   width: 100%;
   height: 50px;
   background: blue;
   position: fixed;
   bottom: 0;
}

FIDDLE Example

在我的例子中,无论最小高度是多少,页脚总是贴在浏览器的底部。

最佳答案

对不起,我误解了你之前的问题。也许这就是您要找的东西?

* {
      margin: 0;
    }
    html, body {
      min-height: 400px;
      height: auto;
      width: 100%;
      margin: 0;
      padding: 0;
      position: relative;
    }
    header {
      width: 100%;
      height: 50px;
      background: blue;
      position: fixed;
      top: 0;
    }
    #content {
      width: 85%;
      margin: 0 auto;
      padding: 50px 0;
    }
    footer {
      width: 100%;
      height: 50px;
      background: blue;
      position: absolute;
      bottom: 0;
    }

JSFiddle example

关于javascript - CSS 将固定页脚对齐到主体最小高度的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19759549/

相关文章:

javascript - 我如何在 jquery 的帮助下在 codeigniter 中匹配两个电子邮件地址

javascript - Jquery json : Uncaught TypeError: Cannot read property 'xx' of undefined

jQuery 将类添加到 html 引用并转义

javascript - 同时运行 2 个 html 视频 JS

html - CSS 对齐列表

javascript - 某些 JavaScript 不会在 WordPress 上加载

javascript - 再次将 Canvas 像素设置为透明

javascript - JS中如何对数字和字符串进行排序,同时保持字符串在前,数字在后排序?

javascript - 在多个按钮中调用相同的 jQuery 函数

jquery - 当用户点击页面某处时关闭所有子菜单