首页 > 解决方案 > 即使位置设置为绝对,页脚也保持固定

问题描述

我正在尝试设计一个应该位于页面底部的简单页脚。换句话说,如果页面很长,用户需要向下滚动才能看到它。不知何故,页脚拒绝停留在那里,而是始终在浏览器窗口的底部可见。我认为只有将其位置设置为固定而不是绝对时才会发生这种情况。我是 Rails 新手,最重要的是,默认情况下会在项目中安装引导程序。认为这不会是一个问题,因为我不使用默认的页脚类。任何想法为什么会这样?

在 _footer.scss 中:

.footer-artcollabs {
  background-color: $grey-light-med;
  height: 72px;
  position: absolute;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  p {
    margin: 0 30px 4px 30px;
  }
}

.foot-logo-container {
  margin-left: 30px;
  width: 44px;
  height: 42px;
}

在 _footer.html.erb 中:

<div class="footer-artcollabs">

  <div class="foot-logo-container">
    <%= render 'shared/logo' %>
  </div>
</div>

标签: htmlcssfooter

解决方案


 position: absolute;
  bottom: 0;

这是将其粘贴到页面底部。

https://www.w3schools.com/css/css_positioning.asp


推荐阅读