html - 无法基于 Bootstraps sticky footer for mobile 创建粘性页脚

标签 html css

我正在尝试模拟这里完成的这个版本的粘性页脚 https://getbootstrap.com/docs/4.1/examples/sticky-footer/

这是我的html代码

<body>
    @Html.Partial("Navigation/_Navigation")
    <div class="container body-content">
        <div class="content-container">
            @RenderBody()
        </div>
        <footer>
            &copy; @DateTime.Now.Year - Stardocs Services
        </footer>
    </div>
</body>

这是我的CSS

html {

}

body {
    padding-top: 50px;
    margin-bottom: 50px;
}

/* Set padding to keep content from hitting the edges */
.body-content {
    padding-top: 20px;
    padding-left: 15px;
    padding-right: 15px;
}

.content-container {

}

/*Footer*/
footer {
    position: absolute;
    bottom: 0;
    left:0;
    width: 100%;
    height: 50px;
    line-height: 50px;
    background-color: #f5f5f5;
}

当我在桌面模式下查看它时,它会很好地固定在底部。但是,当我调整屏幕大小时,该栏看起来像这样:

enter image description here

我不确定如何继续我所做的。

最佳答案

你需要添加

.body-content { 
  min-height: 100vh; 
  padding-bottom: 50px; 
  position: relative;
}

另外,你应该删除

body { margin-bottom: 50px; }

关于html - 无法基于 Bootstraps sticky footer for mobile 创建粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52511748/

相关文章:

html - Thymeleaf:未找到和应用 css 路径

Javascript:在自定义元素上使用自定义属性时,getAttribute 抛出意外标识符

html - 多行文本填充

html - 如何覆盖异步CSS?

javascript - 如何隐藏 Firefox 上下文菜单以显示我自己的菜单?

html - 无法使用 goquery : some nodes are missing 收集 Google 搜索结果的所有节点

javascript - 保持元素在父元素的底部

jquery - CSS 背景图片 onclick

jquery - 无法让行正确显示

javascript - 修改默认浏览器行为,使图像以最大分辨率加载