Bootstrap 4 - 粘性页脚 - 动态页脚高度

Sam*_*ver 3 html css sticky-footer twitter-bootstrap bootstrap-4

我需要把一个棘手的页脚我的网页上,但我没有一个明确的高度,我的页脚设置.在较小的屏幕上 - 行调整大小,页脚变长.

因此,getbootstrap上提供的默认粘性页脚示例不起作用,因为它需要固定的页脚高度.

有没有办法实现这个?

/* Sticky footer styles
-------------------------------------------------- */
html {
  position: relative;
  min-height: 100%;
}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  line-height: 60px; /* Vertically center the text there */
  background-color: #f5f5f5;
}


/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */

body > .container {
  padding: 60px 15px 0;
}

.footer > .container {
  padding-right: 15px;
  padding-left: 15px;
}

code {
  font-size: 80%;
}
Run Code Online (Sandbox Code Playgroud)

Zim*_*Zim 17

现在Bootstrap 4是flexbox,可以使用...来粘贴页脚

<wrapper class="d-flex flex-column">
    <nav>
    </nav>
    <main class="flex-fill">
    </main>
    <footer>
    </footer>
</wrapper>

body, wrapper {
   min-height:100vh;
}

.flex-fill {
   flex:1 1 auto;
}
Run Code Online (Sandbox Code Playgroud)

演示:Bootstrap 4 Sticky Footer(4.0.0)

注:flex-fill实用程序类将被列入下一个引导程序4.1版本.因此,在该版本之后,将不需要额外的用于flex-fill的CSS.


小智 5

一个非常简单的方法是使用导航栏作为页脚。它带有一个非常方便的固定底部类。要更改间距,您可以在此处查看文档... https://getbootstrap.com/docs/4.2/utilities/spacing/

<nav class="navbar fixed-bottom navbar-light bg-light">
  <a class="navbar-brand" href="#">Fixed bottom</a>
</nav>
Run Code Online (Sandbox Code Playgroud)