html - Bootstrap 页脚位于页面中间

标签 html css twitter-bootstrap

我有一个像这样的 Blade 主模板,它允许我使用一个模板来容纳许多不同的容器,如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>
        @yield('title')
    </title>

    @include('libs.libs')
    @include('google.analytics')

</head>
<body>
    @include('partials.nav_sched')

    <div class="container">
        @yield('content')
    </div>

    @yield('schedule')

</body>
<div class="panel-footer navbar-bottom">
    @include('partials.footer-sched')
</div>
</html>
@include('js.libs')
@include('js.add-class')

问题是,我的页脚位于页面中间:

enter image description here

这是我的partials/footer-sched:

<div class="container">
    <p class="text-muted text-center">
        Made with ♥ by Drexel Students for Drexel Students
    </p>
    <h6 class="text-muted text-center">
        <small>
            <a href="http://www.contact.com/contact-me/">Contact Me</a>
        </small>
    </h6>
</div>

我尝试了很多方法,例如使用自定义 CSS 将页脚从主体中取出:

.panel-footer{
  padding-top: 40px;
  padding-bottom: 40px;
  margin-top: 40px;
  border-top: 1px solid #eee;
  background-color: #ffffff;
}

我只是无法将页脚放在页面底部。我不想要粘性页脚,但我只想要一个位于页面底部的页脚。

最佳答案

尝试使用这个:

  1. 将新类“contentHeight”添加到 container包含所有内容的 div,或者是顶部导航和底部页脚之间的中间 div。

  2. 在您的 html 代码的底部添加它,就在 body 之前标签结束

<script>

var canvasHeight = $(window).height();

var navHeight = $('.nav').height(); //'nav' this should be replaced with class name which your navigation has in original

var footerHeight = $('.panel-footer').height();

var addHeight = canvasHeight - (navHeight + footerHeight)

$(document).ready(function (){

$('.contentHeight').css('min-height', addHeight)

});

</script>

  1. 您在问题中发布的代码显示 <div class="panel-footer navbar-bottom">...</div>关外</body>标签。把这个放进去。

  2. 删除所有 position: absolute;来自页脚 div 的 css 以将其恢复为正常的 html 流。

关于html - Bootstrap 页脚位于页面中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32172463/

相关文章:

html - 可用于创建以下页面布局的最少 div 数量是多少?

html - 在 bootstrap 3.3.5 中更改导航宽度(从 1170px 到 940px)

html - 使用 Bootstrap 在页面上制作图像中心

php - 如何在 laravel 中使用 ajax post 请求将图像插入数据库?

javascript - 如何根据 jQuery 中的滚动位置将 addClass() 添加到两个不同导航的事件链接?

html - 两个盒子的背景颜色相同(左和右),但左框内容很多,右框内容很少?

javascript - 为什么我的 JS 代码只运行一次?

html - 如何并排对齐 4 张照片,以及它们下面的单独文字?

css - 如何使用 Twitter Bootstrap 正确放置两个内联输入字段?

twitter-bootstrap - Twitter Bootstrap 词缀 : Can't pin