html - 使div固定在页面底部

标签 html css

所以我制作了一个联系页面,我希望页脚 div 粘在页面底部,而不是紧跟在联系表格之后。

但如果我将所有内容放入 height:100%; 的容器 div 并制作页脚 bottom:0; 那么页面将是“太长”,你必须滚动等......

到目前为止我的 css:

#footer{
    background-color:#fff;
    font:bold 14px;
    color:#1E88E5;
    width:100%;
    height:auto;
    padding:1%;
    border-top:1px solid #1E88E5;
}

页脚只是一个普通的全宽 div,带有一些居中的文本 atm。

最佳答案

你或许可以使用 position: fixed 来实现这一点。

.footer {
  position: fixed;
  bottom: 0;
}

有了这个,您将需要偏移页面底部,因此建议将 padding-bottom 添加到 .main,这是页脚的高度。

.main {
  padding-bottom: 30px /*whatever the height of your footer is*/
}

关于html - 使div固定在页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39099295/

相关文章:

html - 如何使div从下到上放置

html - 头部的 CSS 框阴影具有粘性位置

javascript - 使用 AngularJS 为每个页面添加导航和页脚

css - 使用 CSS 定位工具提示

css - Bootstrap 静态布局 "visual"左右排水沟 firefox chrome

css - 我可以使用 Markdown 在段落上定义类名吗?

php - 图片/文件上传不适用于 materializecss 框架

javascript - 设置CSS的背景图片:before tag programatically

html - Bootstrap 3 - 屏幕调整大小时导航栏内容消失 - 不会折叠

javascript - 试图覆盖动态生成的内联样式