html - css页脚总是在页面底部

标签 html css

如何使页脚始终位于页面底部(无粘性)?我的页脚位于屏幕底部,但不在页面上。

这是我的代码示例。

HTML

<!DOCTYPE html>
<html>
<head>
     <meta http-equiv="Content-Type" content="text/html charset=utf-8"/>
     <link href="styles.css" type="text/css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="header">Header</div>
        <div class="body">Body</div>
        <div class="footer">Footer</div>
    </div>
</body>
</html>

CSS

.footer {
    width:100%;
    height:109px;
    position:absolute;
    bottom:0;
    left:0;
    background-color: purple;
}

最佳答案

<style>
  
.demo {
  margin: 0 auto;
  padding-top: 64px;
  max-width: 640px;
  width: 94%;
}

.footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background-color: #efefef;
  text-align: center;
}
</style>
<div class="demo">
  <h1>CSS “Always on the bottom” Footer</h1> 
</div>


<div class="footer">This footer will always be positioned at the bottom of the page, but <strong>not fixed</strong>
</div>

关于html - css页脚总是在页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44400585/

相关文章:

html - 2个div,每个包含2个div并且响应

javascript - 如何使用 jQuery 知道何时取消选择 &lt;input&gt; 元素

html - Bootstrap 和 LESS。导航栏不起作用

html - 名称为 ='' 的无效表单控件不可聚焦

javascript - 重叠标签 JS CSS HTML

html - 在不同屏幕(台式机、笔记本电脑、移动设备)上调整绝对面板和其中的文本的大小

javascript - 如何让第二个 div 始终与第一个 div 具有相同的高度?

javascript - 单击滑动到可滚动 div JQuery 中的内容

Jquery-UI 自动完成自定义数据 - 图像不会在自动完成的下拉列表中呈现

javascript - Bootstrap 模式无法正常工作