css - 将 div 定位在页面或屏幕的底部

标签 css twitter-bootstrap

我制作了一个页 footer 分,它位于我网页的底部。当我的网页内容小于浏览器视口(viewport)的高度时,我遇到了一个问题,这在页脚和页面末尾之间留下了空白。我试图通过使用这段 css 来解决它。

.footer {
  position: absolute;
  bottom: 0;
  height: 125px;
}

它在我的内容很少的网页上运行完美,但对于大网页,页脚与内容重叠。我按照一些在线教程进行操作,但仍然无法正确完成。

<body class="bg-1">
<div class="container-full">
    <div class="container">
        ...
    </div>
</div>

<div class="footer text-center">
   ...
</div>
</body>

.container-full {
  width: 100%;
  height: 100%;
  padding-top: 70px;
  margin: 0 auto 125px;
}
.bg-1 {
  background: url(../img/1.png) no-repeat center center fixed;
  background-size: cover;
  height: 100%;
}
.footer {
  position: absolute;
  bottom: 0;
  height: 125px;
}

我正在使用 Twitter Bootstrap。

最佳答案

您可以尝试以下方法:

html,
body {
  height: 100%;
}
.container-full {
  table-layout: fixed;
  background: #ccc;
  display: table;
  height: 100%;
  width: 100%;
}

.footer {
  display: table-footer-group;
  background: #2f2f2f;
  overflow: hidden;
  color: #fff;
  width: 100%;
  height: 1%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<body class="bg-1">
  <div class="container-full">
    <div class="container">
      <p>Main Content goes here</p>
    </div>
    <div class="footer text-center">
      <p>Footer text goes here..</p>
    </div>
  </div>
</body>

关于css - 将 div 定位在页面或屏幕的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38518703/

相关文章:

html - 双图背景不用css加class

css - 当没有使用 Bootstrap 和 MVC5 的随附标签时,复选框输入对齐不当

jquery - 使用 Bootstrap,我需要替换我的 div 的顺序

javascript - Carousel slick.js + bootstrap 列宽问题

html和css布局问题

html - 如何在点击按钮时暂停 YouTube 视频?

html - 如何解决背景图像在 CSS 中不显示的问题

html - Font Awesome Styling Q(内嵌按钮)

css - 如何在 Bootstrap 3 中垂直对齐文本旁边的图标

css - Rails Bootstrap 2.3.1 导航栏颜色