Bootstrap 4 - 粘性页脚 - 动态页脚高度 [英] Bootstrap 4 - Sticky footer - Dynamic footer height

查看:24
本文介绍了Bootstrap 4 - 粘性页脚 - 动态页脚高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的页面上放置一个粘性页脚,但是我没有为我的页脚设置明确的高度.在较小的屏幕上 - 行调整大小,页脚变长.

I need to put a sticky footer on my pages , however i don't have a definite height set for my footer . On smaller screens - the rows resize and footer becomes longer .

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

Therefore , the default sticky footer example provided on getbootstrap does not work since it requires a fixed footer height.

有什么方法可以实现吗?

Any way to implement this ?

/* 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%;
}

推荐答案

既然 Bootstrap 4 是 flexbox,可以使用...

Now that Bootstrap 4 is flexbox, a sticky footer can be done using...

<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;
}

演示:Bootstrap 4.0 粘性页脚

注意:flex-fill 实用程序类是 包含在 Bootstrap 4.1 及更高版本 中.所以在那之后发布额外的 flex-fill 的 CSS 就不需要了.

Note: The flex-fill utility class is included in the Bootstrap 4.1 and later release. So after that release the extra CSS for flex-fill won't be needed.

Bootstrap 4.1 开始,有一个 min-vh-100 实用程序类,这意味着您不需要额外的 CSS.

As of Bootstrap 4.1, there is a min-vh-100 utility class which means you don't need the extra CSS.

演示:Bootstrap 4.1+ 粘性页脚

这篇关于Bootstrap 4 - 粘性页脚 - 动态页脚高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆