Bootstrap 3 100%高度DIV,带有Navbar和Sticky Footer

时间:2016-04-29 19:21:12

标签: html css twitter-bootstrap

我有一个使用固定导航栏和粘性页脚的布局。在主体中,我有一个流体容器,柱子左边对齐。我希望该列垂直填充主体(在导航栏和页脚之间),但是我无法让它工作。我已经尝试了所有我能找到的例子,但没有用。

我已经构建了这个JSFiddle来展示我到目前为止所拥有的内容。

这是我希望实现的目标:

enter image description here

我的HTML:

<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6 ">
      <div class="main-content">
        <h1>Hello world.</h1>
      </div>
    </div>
  </div>
</div>

<footer class="footer">
    <div class="container">
        Sticky footer based on <a href="http://getbootstrap.com/examples/sticky-footer-navbar/">Boostrap example</a>.
    </div>
</footer>

我的CSS:

/* 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;
  background-color: #999999;
}

/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */
body > .container-fluid {
  padding-top: 50px;
}
.container-fluid .col-sm-6 {
  padding: 0;
}
.navbar {
  margin-bottom: 0;
}
.footer {
  padding: 15px 0;
}

.main-content {
  background: #efefef;
  padding: 20px;
  height: 100%;
  min-height: 100%;
}

1 个答案:

答案 0 :(得分:4)

您可以在height:calc(100vh - 110px); div上使用.main-content。 110px是页脚的高度+标题的高度,从视口高度中减去。

http://www.bootply.com/v8XITHB4fP

相关问题