使用Twitter Bootstrap将页脚粘贴到页面底部

Ric*_*wis 71 css twitter-bootstrap

我有一些网页内容不多,页脚位于页面中间,但我希望它位于底部.

我已将所有页面都放在"持有者"中

#holder {
  min-height: 100%;
  position:relative;
}
Run Code Online (Sandbox Code Playgroud)

然后使用以下CSS作为我的页脚

ul.footer {
  margin-top: 10px;
  text-align: center;
}

ul.footer li {
  color: #333;
  display: inline-block;
}

#footer {
  bottom: -50px;
  height: 50px;
  left: 0;
  position: absolute;
  right: 0;
}
Run Code Online (Sandbox Code Playgroud)

我的页脚的HTML

<div class="container">
  <div class="row">
    <div class="span12">
      <div id="footer">
        <ul class="footer">
          <li>Website built by <a href="#">Fishplate</a></li>&nbsp;&nbsp;
          <li>Email:exampleemail@gmail.com</li>
        </ul>
      </div>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想保持页脚流畅.

Jon*_*Jon 83

只需将navbar-fixed-bottom类添加到页脚即可.

<div class="footer navbar-fixed-bottom">
Run Code Online (Sandbox Code Playgroud)

  • 这创建了一个冻结的页脚,内容在其下方向上滚动.我错过了什么吗?谢谢. (7认同)
  • 从 Bootstrap 4 开始,“navbar-fixed-bottom”不再是“navbar-fixed-bottom”,而是“fixed-bottom” (4认同)

My *_*rts 40

正如您在评论中所讨论的那样,您的代码基于此解决方案:https://stackoverflow.com/a/8825714/681807

此解决方案的关键部分之一是添加height: 100%,html, body因此#footer元素具有可用的基本高度 - 这在您的代码中缺失:

html,body{
    height: 100%
}
Run Code Online (Sandbox Code Playgroud)

您还会发现使用时会遇到问题,bottom: -50px因为当内容不多时,这会将您的内容推送到折叠状态.你必须在之前添加margin-bottom: 50px到最后一个元素#footer.


Bla*_*ard 9

大多数上述解决方案对我没有用.但是,下面给出的解决方案工作正常:

<div class="fixed-bottom">...</div>      
Run Code Online (Sandbox Code Playgroud)

资源

  • 工作但覆盖内容 (6认同)

eas*_*wee 8

http://bootstrapfooter.codeplex.com/

这应该可以解决您的问题.

<div id="wrap">
<div id="main" class="container clear-top">
<div class="row">
<div class="span12">
Your content here.
</div>
</div>
</div>
</div>
<footer class="footer" style="background-color:#c2c2c2">
</footer>
Run Code Online (Sandbox Code Playgroud)

CSS:

html,body
{
height:100%;
}

#wrap
{
min-height: 100%;
}

#main
{
overflow:auto;
padding-bottom:150px; /* this needs to be bigger than footer height*/
}

.footer
{
position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;
padding-top:20px;
color:#fff;
}
Run Code Online (Sandbox Code Playgroud)


Vic*_*tor 6

以下是使用css3的示例:

CSS:

html, body {
    height: 100%;
    margin: 0;
}
#wrap {
    padding: 10px;
    min-height: -webkit-calc(100% - 100px);     /* Chrome */
    min-height: -moz-calc(100% - 100px);     /* Firefox */
    min-height: calc(100% - 100px);     /* native */
}
.footer {
    position: relative;
    clear:both;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="wrap">
    <div class="container clear-top">
       body content....
    </div>
</div>
<footer class="footer">
    footer content....
</footer>
Run Code Online (Sandbox Code Playgroud)

小提琴


Cod*_*ast 6

使用引导类对您有利.navbar-static-bottom把它留在底部.

<div class="navbar-static-bottom" id="footer"></div>
Run Code Online (Sandbox Code Playgroud)