c# - 强制页脚停留在渲染页面的底部

标签 c# html css asp.net-mvc

嘿,我试图在添加内容时强制页脚移动到页面底部。 类似于:http://jsfiddle.net/eTwJh/2/ .我将 asp.net mvc 与布局页面一起使用,其中 View 通过 @RenderBody() 呈现为布局页面“主体”。

附言使用 position: relative for footer 和 body-content 现在强制页脚停留在页面底部,但现在打开页面时,页脚位于页面的一半(html 末尾) min-height: 100% on body 元素似乎没有任何效果..

屏幕截图:Footer not staying at the bottom of the page

Chrome 检查元素:http://imgur.com/BWuFxn2

这是我的代码 Layout.cshtml 页面:

 <body>
 ....
 <div class="container body-content" style="position:relative">
    @RenderBody()
</div>
<footer>
    <p>&copy; @DateTime.Now.Year Some Text</p>
</footer>

@if (!User.Identity.IsAuthenticated)
{
<!-- BEGIN # MODAL LOGIN -->
<div class="modal fade" id="login-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content" id="modal-content">
        </div>
    </div>
</div>
<!-- END # MODAL LOGIN -->
}
</body>
</html>

这是我的 CSS:

footer {
  clear: both;
  background-color: #000;
  width: 100%;
  padding: 20px 0;
  border-bottom: 1px solid #5c5c5c;
  position: absolute;
  bottom: 0px;
}

footer p {
    padding-left: 5px;
    color: #fff;
    display: table-cell;
}

最佳答案

确保您的 body-content 和 footer 类的位置都设置为 relative。在 fiddle 中,它被设置为 absolute 因为页脚在包装器内部,而 bottom: 0 将它推到包装器的底部。

或者简单地为这两个 div 创建一个包装器,就像在提供的 fiddle 中一样。

关于c# - 强制页脚停留在渲染页面的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44434554/

相关文章:

javascript - 动态添加子项时如何设置父项可滚动

javascript - 从一个对象悬停到另一个对象,第二个 DOM 对象不会立即消失

c# - 跨平台线程和 GTK#,无法正常工作?

html - 如何将标题放在浏览器的顶部 - CSS3 HTML5

html - 在 bootstrap 4.1 中垂直居中对齐带有背景颜色的 col 文本

javascript - 使用 Javascript 更改 HTML 下拉列表中显示的项目

jquery - 删除输入字段更新

c# - BlockingCollection worker 需要通过匿名函数返回一个值

c# - 在C#Parallel.ForEach中的线程上持久变量

c# - 反序列化时跳过无效值