【问题标题】:Twitter Bootstrap 3 Sticky FooterTwitter Bootstrap 3 粘性页脚
【发布时间】:2013-07-31 17:28:42
【问题描述】:

我使用 twitter 引导框架已经有一段时间了,他们最近更新到了第 3 版!

我无法让粘性页脚粘在底部,我使用了 twitter bootstrap 网站提供的起始模板,但仍然没有运气,有什么想法吗?

【问题讨论】:

标签: html css twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

只需将类 navbar-fixed-bottom 添加到您的页脚。

<div class="footer navbar-fixed-bottom">

【讨论】:

  • 这与置顶页脚不同
  • 如果您有页眉和页脚,则会在移动设备上浪费太多空间。
  • @strattonn 这就是媒体查询的用途
  • 如果页面不需要滚动,这将非常有效。但是页脚与页面上的更多内容重叠。对此有任何解决方法吗?谢谢!
  • 不确定重叠问题,但添加边距/填充不能解决问题吗?
【解决方案2】:

参考官方 Boostrap3 粘页脚示例, 不用加&lt;div id="push"&gt;&lt;/div&gt;,CSS更简单。

官方示例中使用的CSS是:

/* Sticky footer styles
-------------------------------------------------- */

html,
body {
  height: 100%;
  /* The html and body elements cannot have any padding or margin. */
}

/* Wrapper for page content to push down footer */
#wrap {
  min-height: 100%;
  height: auto;
  /* Negative indent footer by its height */
  margin: 0 auto -60px;
  /* Pad bottom by footer height */
  padding: 0 0 60px;
}

/* Set the fixed height of the footer here */
#footer {
  height: 60px;
  background-color: #f5f5f5;
}

和基本的 HTML:

<body>

    <!-- Wrap all page content here -->
    <div id="wrap">

      <!-- Begin page content -->
      <div class="container">
        
      </div>
    </div>

    <div id="footer">
      <div class="container">
       
      </div>
    </div>
</body>

你可以在sticky-footer example的源代码中找到这个css的链接。

<!-- Custom styles for this template -->
<link href="sticky-footer.css" rel="stylesheet">

完整网址: https://getbootstrap.com/docs/3.4/examples/sticky-footer/sticky-footer.css

【讨论】:

  • 官方粘性页脚示例中的 HTML 和 CSS 现在与此处描述的完全不同,例如不再使用 'wrap' div。
【解决方案3】:

这是一种添加粘性页脚的方法,除了 Bootstrap 中已有的内容之外,不需要任何额外的 CSS 或 Javascript,并且不会干扰您当前的页脚。

此处示例:Easy Sticky Footer

只需将其复制并直接粘贴到您的代码中即可。不要大惊小怪。

<div class="navbar navbar-default navbar-fixed-bottom">
    <div class="container">
      <p class="navbar-text pull-left">© 2014 - Site Built By Mr. M.
           <a href="http://tinyurl.com/tbvalid" target="_blank" >HTML 5 Validation</a>
      </p>

      <a href="http://youtu.be/zJahlKPCL9g" class="navbar-btn btn-danger btn pull-right">
      <span class="glyphicon glyphicon-star"></span>  Subscribe on YouTube</a>
    </div>
</div>

【讨论】:

  • 非常好和快。也可以反应灵敏。但是需要在页面内容的底部添加一些额外的空间,这样它就不会被页脚隐藏。该空间的高度应等于页脚高度。 你能说明如何最好地做到这一点吗?顺便说一句,“不需要任何 CSS” 在技术上是错误的。它应该是“除了 Bootstrap 类之外不需要任何额外的 CSS”.
  • 我喜欢这利用了引导程序中现有的内容。我无法获得其他最佳答案,但将其粘贴在我的页面和粘滞页脚中。谢谢!
【解决方案4】:

除了刚才添加的CSS,记得在关闭wrap div之前需要添加push div

HTML 的基本结构是

<div id="wrap"> 
    page content here 
    <div id="push"></div>
</div> <!-- end wrap -->

<div id="footer">
    footer content here
</div> <!-- end footer -->

Live view
Edit view

【讨论】:

  • 如果页面内容大于可用显示,页脚将被下推。我希望页脚真正粘在底部(如 navbar-fixed-bottom)
  • 嘿@delavnog,这样的东西适合你吗? codepen.io/panchroma/pen/wMXWpY 。对您来说唯一重要的部分是第 647 行的 HTML 和 CSS
  • @delavnog ,同样的想法,页面上的内容最少 codepen.io/panchroma/pen/JGZKqy
  • 谢谢,太好了!现在,如果我能让主 div 在导航和页脚之间垂直居中,那就太棒了!编辑了您的代码笔:codepen.io/anon/pen/rxKMaW(我必须在正文中添加一个边距,因为导航占用了内容的顶部)
  • @delavnog ,如果主体不是太高,这是一个开始。不过对于更长的内容,这需要更多的工作:codepen.io/panchroma/pen/vLrXMq
【解决方案5】:

这是今天的Sticky Footer simplified code,因为他们一直在优化它,这很好:

HTML

<!DOCTYPE html>
<html lang="en">
  <head></head>

  <body>

    <!-- Fixed navbar -->
    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <!-- Begin page content -->
    <div class="container">
      <div class="page-header">
        <h1>Sticky footer with fixed navbar</h1>
      </div>
      <p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
      <p>Back to <a href="../sticky-footer">the default sticky footer</a> minus the navbar.</p>
    </div>

    <footer>
      <div class="container">
        <p class="text-muted">Place sticky footer content here.</p>
      </div>
    </footer>

  </body>
</html>

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: #f5f5f5;
}

【讨论】:

  • 完美解决方案。这就是我一直在寻找的。​​span>
  • 不幸的是,这个页脚的大小是固定的。有时,当页脚是动态的时,它可以大于或小于它在 CSS 中的高度。
【解决方案6】:

我在这个问题上有点晚了,但我遇到了这篇文章,因为我刚刚被这个问题所困扰,终于找到了一个非常简单的方法来克服它,只需使用 navbar 和 @987654322 @类启用。例如:

<div class="navbar navbar-default navbar-fixed-bottom">
  <div class="container">
    <span class="navbar-text">
      Something useful
    </span>
  </div>
</div>

HTH

【讨论】:

  • 我喜欢你的回答简单而有效,顺便说一句,这是一个聪明的回答。同一问题的许多答案都充满了 jquery 和复杂的东西。谢谢大佬。
  • 解决了一半,如果调整大小,您仍然需要注意页面内容的重叠。
  • @Baldráni 不,它是一个完整的解决方案,如果您在页脚 html 中使用 Bootstrap 行和列(这是您应该做的),重叠工作正常
  • 这不是粘性页脚。它是一个固定底部导航栏,只适用于导航栏内容,与页面内容重叠。
【解决方案7】:

这是我对此问题的最新解决方案。

 /* 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: #f5f5f5;

  border-top: 1px solid #eee;
  text-align: center;
}

.site-footer-links {
  font-size: 12px;
  line-height: 1.5;
  color: #777;
  padding-top: 20px;
  display: block;
  text-align: center;
  float: center;
  margin: 0;
  list-style: none;
} 

并像这样使用它:

<div class="footer">
 <div class="site-footer">
  <ul class="site-footer-links">
        <li>© Zee and Company<span></span></li>
  </ul>
 </div>

</div>

或者

html, body {
  height: 100%;
}
.page-wrap {
  min-height: 100%;
  /* equal to footer height */
  margin-bottom: -142px; 
}
.page-wrap:after {
  content: "";
  display: block;
}
.site-footer, .page-wrap:after {
  height: 142px; 
}
.site-footer {
  background: orange;
}

【讨论】:

  • 这不是一个好的解决方案,因为您的页脚是固定的,这意味着它与页面内容(如果有)重叠。尝试在页脚前添加几行some text&lt;br&gt; 并缩小窗口大小。
  • @user2041318:是的,这太可怕了……谢谢你指出这一点。
  • 这已根据 jmarceli 评论更正。页脚不再固定。
【解决方案8】:

粘性示例对我不起作用。 我的解决方案:

#footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 3em;
}

【讨论】:

  • 简单、良好的老式 CSS。任务完成。我觉得有趣的是,一些评分较高的答案是多么令人费解。 Bootstrap 不应该让我们的生活更轻松吗? ?
【解决方案9】:

推送div 应该紧跟在wrap 之后,而不是在......就像这样

<div id="wrap">
  *content goes here*
</div>

<div id="push">
</div>

<div id="footer">
  <div class="container credit">
  </div>
  <div class="container">
    <p class="muted credit">© Your Page 2013</p>
  </div>
</div>

【讨论】:

    【解决方案10】:

    由 OP 回答:

    将此添加到您的 CSS 文件中。

    html,
    body {
      height: 100%;
      /* The html and body elements cannot have any padding or margin. */
    }
    /* Wrapper for page content to push down footer */
    #wrap {
      min-height: 100%;
      height: auto !important;
      height: 100%;
      /* Negative indent footer by it's height */
      margin: 0 auto -60px;
    }
    
    /* Set the fixed height of the footer here */
    #push,
    #footer {
      height: 60px;
    }
    #footer {
      background-color: #eee;
    }
    
    /* Lastly, apply responsive CSS fixes as necessary */
    @media (max-width: 767px) {
      #footer {
        margin-left: -20px;
        margin-right: -20px;
        padding-left: 20px;
        padding-right: 20px;
      }
    }
    

    【讨论】:

      【解决方案11】:

      我想要一个灵活的粘性页脚,这就是我来这里的原因。热门答案让我朝着正确的方向前进。

      当前(16 年 10 月 2 日)Bootstrap 3 css Sticky footer(固定大小)如下所示:

      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: #f5f5f5;
      }
      

      只要页脚有一个固定的大小,body margin-bottom 就会创建一个推力,让页脚可以放入一个口袋。在这种情况下,两者都设置为 60 像素。但是如果页脚不固定,超过 60px 高度,就会覆盖你的页面内容。

      使灵活:删除 css 正文边距和页脚高度。然后添加 JavaScript 以获取页脚高度并设置正文 marginBottom。这是通过 setfooter() 函数完成的。接下来添加事件侦听器,用于页面首次加载和调整运行 setfooter 的大小。注意:如果您的页脚有手风琴或其他任何触发大小更改的东西,而没有调整窗口大小,您必须再次调用 setfooter() 函数。

      运行 sn-p 然后全屏演示。

      function setfooter(){
      	var ht = document.getElementById("footer").scrollHeight;
      	document.body.style.marginBottom = ht + "px";
      }
      
      window.addEventListener('resize', function(){
      		setfooter();
      	}, true);
      window.addEventListener('load', function(){
      	setfooter();
      }, true);
      html {
        position: relative;
        min-height: 100%;
      }
      .footer {
        position: absolute;
        bottom: 0;
        width: 100%;
        
        /* additional style for effect only */
         text-align: center;
          background-color: #333;
          color: #fff;
      }
        
      
      
      body{
      /* additional style for effect only not needed in bootstrap*/
        padding:0;
        margin: 0;
        }
      <div>
        Page content
        <br>  <br>
        line 3
        <br>  <br>
        line 5
        <br>  <br>
        line 7
        
       </div>
      
      
      <footer id="footer" class="footer">
            <div class="container">
              <p class="text-muted">Footer with a long text, so that resizing, to a smaller screen size, will cause the footer to grow taller. But the footer will not overflow onto the main page.</p>
            </div>
          </footer>

      【讨论】:

        【解决方案12】:

        这已经被 flexbox 解决了,一劳永逸:

        https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/

        HTML

        <body class="Site">
          <header>…</header>
          <main class="Site-content">…</main>
          <footer>…</footer>
        </body>
        

        CSS

        .Site {
          display: flex;
          min-height: 100vh;
          flex-direction: column;
        }
        
        .Site-content {
          flex: 1;
        }
        

        【讨论】:

          【解决方案13】:

          简单的js

          if ($(document).height() <= $(window).height()) {
              $("footer").addClass("navbar-fixed-bottom");
          }
          

          更新 #1

          $(window).on('resize', function() {
              $('footer').toggleClass("navbar-fixed-bottom", $(document).height() <= $(window).height());
          });
          

          【讨论】:

            【解决方案14】:

            总结所有这些,请记住一件事,即除了页脚之外的所有内容都应该有 min-height: 100% 或更少。

            【讨论】:

              【解决方案15】:

              我使用 LESS 编写了带有填充的简化粘性页脚代码。这个答案可能是题外话,因为这个问题没有讨论填充,所以如果你有兴趣查看this post了解更多详情。

              @footer-padding:      40px;  // Set here the footer padding
              @footer-inner-height: 150px; // Set here the footer height (without padding)
              
              /* Calculates the overall footer height */
              @footer-height: @footer-inner-height + @footer-padding*2;
              
              html {
               position: relative;
               min-height: 100%;
              }
              body {
               /* This avoids footer to overlap the page content */
               margin-bottom: @footer-height;
              }
              footer{
               /* Fix the footer on bottom and give it fixed height */
               position: absolute;
               bottom: 0;
               width: 100%;
               height: @footer-height;
               padding: @footer-padding 0;
              }
              

              【讨论】:

                【解决方案16】:

                基于Jek-fdrv's answer,我添加了.on('resize', function(),以确保它适用于所有设备和每种分辨率:

                $(window).on('resize', function() {
                    if ($(document).height() <= $(window).height()) {
                        $('footer').addClass("navbar-fixed-bottom");
                    } else {
                        $('footer').removeClass("navbar-fixed-bottom");
                    }
                });
                

                【讨论】:

                  【解决方案17】:

                  当前版本的 bootstrap 似乎不再适用于此功能。如果您下载他们的sticky-footer-navbar 示例并在主体区域中放置大量内容,则页脚将被向下推到视口底部。一点都不粘。

                  【讨论】:

                    【解决方案18】:

                    这是一个基于 CSS 的完全响应式可变高度粘性页脚解决方案。
                    优势:页脚允许可变高度,因为高度不再需要在 CSS 中进行硬编码。

                    body {
                      display: -webkit-box;
                      display: -webkit-flex;
                      display: -moz-box;
                      display: -ms-flexbox;
                      display: flex;
                      -webkit-box-orient: vertical;
                      -webkit-box-direction: normal;
                      -webkit-flex-direction: column;
                         -moz-box-orient: vertical;
                         -moz-box-direction: normal;
                          -ms-flex-direction: column;
                              flex-direction: column;
                      min-height: 100vh;
                    }
                    body > * {
                      -webkit-box-flex: 0;
                      -webkit-flex-grow: 0;
                         -moz-box-flex: 0;
                          -ms-flex-positive: 0;
                              flex-grow: 0;
                    }
                    body > nav + .container {
                      -webkit-box-flex: 1;
                      -webkit-flex-grow: 1;
                         -moz-box-flex: 1;
                          -ms-flex-positive: 1;
                              flex-grow: 1;
                    }
                    
                    
                    
                    /* Reset CSS and some footer styling. Only needed on StackOverflow */
                    body {
                      padding: 50px 0 0;
                      margin: 0;
                    }
                    footer {
                      background-color: #f8f8f8; 
                      padding: 15px 0 5px; 
                      border-top: 1px solid #e7e7e7;
                    }
                    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
                    <!DOCTYPE html>
                    
                         <!-- Fixed navbar -->
                        <nav class="navbar navbar-default navbar-fixed-top">
                          <div class="container">
                            <div class="navbar-header">
                              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                              </button>
                              <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>
                                <li><a href="#about">About</a></li>
                                <li><a href="#contact">Contact</a></li>
                                <li class="dropdown">
                                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                                  <ul class="dropdown-menu">
                                    <li><a href="#">Action</a></li>
                                    <li><a href="#">Another action</a></li>
                                    <li><a href="#">Something else here</a></li>
                                    <li role="separator" class="divider"></li>
                                    <li class="dropdown-header">Nav header</li>
                                    <li><a href="#">Separated link</a></li>
                                    <li><a href="#">One more separated link</a></li>
                                  </ul>
                                </li>
                              </ul>
                            </div><!--/.nav-collapse -->
                          </div>
                        </nav>
                    
                        <!-- Begin page content -->
                        <div class="container">
                          <div class="page-header">
                            <h1>Responsive sticky footer of any height</h1>
                          </div>
                          <p class="lead">You can have a sticky footer of any height using this CSS. It's also fully responsive, no JavaScript needed.</p>
                          
                        </div>
                    
                        <footer class="footer">
                          <div class="container">
                            <p class="text-muted">Place sticky footer content here.</p>
                            <p class="text-muted">And some more content.</p>
                            <p class="text-muted">And more...</p>
                          </div>
                        </footer>

                    这里是不带前缀的SCSS(对于gulp/grunt):

                    body {
                      display: flex;
                      flex-direction: column;
                      min-height: 100vh;
                      > * {
                        flex-grow: 0;
                      }
                      > nav + .container {
                        flex-grow: 1;
                      }
                    }
                    

                    【讨论】:

                      【解决方案19】:

                      只需使用弹性!确保在您的 HTML 中使用 body 和 main,这是最好的解决方案之一(除非您需要 IE9 支持)。它不需要固定的高度或类似的高度。

                      这也是 Materialise 的推荐方法!

                      body {
                          display: flex;
                          min-height: 100vh;
                          flex-direction: column;
                      }
                      
                      main {
                          flex: 1 0 auto;
                      }
                      

                      【讨论】:

                        【解决方案20】:

                        用 Haml 和 Sass 的话来说都是必要的:

                        app/view/layouts/application.html.haml的Haml

                        %html
                          %head
                          %body
                            Some  body stuff
                        
                            %footer
                              footer content
                        

                        app/assets/stylesheets/application.css.sass 的 Sass

                        $footer-height: 110px
                        
                        html
                          position: relative
                          min-height: 100%
                        
                        body
                          margin-bottom: $footer-height
                        
                        body > footer
                          position: absolute
                          bottom: 0
                          width: 100%
                          height: $footer-height
                        

                        基于http://getbootstrap.com/examples/sticky-footer-navbar/

                        【讨论】:

                          【解决方案21】:

                          如果您想在页脚类中使用引导程序构建。你还应该写一些javascript:

                          $(document).ready(function(){
                            $.fn.resize_footer();
                          
                            $(window).resize(function() {
                              $.fn.resize_footer();
                            });
                           });
                          
                          (function($) {
                          
                            $.fn.resize_footer = function(){
                              $('body > .container-fluid').css('padding-bottom', $('body > footer').height());
                            };
                           });
                          

                          通过固定页脚防止内容重叠,并在用户更改窗口/屏幕大小时调整padding-bottom

                          在上面的脚本中,我假设页脚直接放在 body 标签内:

                          <body>
                            ... content of your page ...
                            <div class="navbar navbar-default navbar-fixed-bottom">
                              <div class="container">
                                <div class="muted pull-right">
                                  Something useful
                                </div>
                                ... some other footer content ...
                              </div>
                            </div>
                          </body>
                          

                          这绝对不是最好的解决方案(因为 JS 是可以避免的),但它工作时没有任何重叠问题,易于实现和响应(height 不是在 CSS 中硬编码)。

                          【讨论】:

                            【解决方案22】:

                            #myfooter{
                            height: 3em;
                              background-color: #f5f5f5;
                              text-align: center;
                              padding-top: 1em;
                            }
                            <footer>
                                <div class="footer">
                                    <div class="container-fluid"  id="myfooter">
                                        <div class="row">
                                            <div class="col-md-12">
                                                <p class="copy">Copyright &copy; Your words</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </footer>

                            【讨论】:

                            • 这个底部怎么粘?
                            【解决方案23】:

                            这是一个非常简单干净的粘性页脚,您可以在引导程序中使用。完全响应!

                            HTML

                            <body>
                            <nav class="navbar navbar-default">
                              <div class="container-fluid">
                                <div class="navbar-header">
                                  <a class="navbar-brand" href="#">
                                    <img alt="Brand" src="">
                                  </a>
                                </div>
                              </div>
                            </nav>
                                <footer></footer>
                            </body>
                            </html>
                            

                            CSS

                            html {
                                position: relative;
                                min-height: 100%;
                            }
                            body {
                                margin: 0 0 100px;
                            }
                            footer {
                                position: absolute;
                                left: 0;
                                bottom: 0;
                                height: 100px;
                                width: 100%;
                                background-color: red;
                            }
                            

                            示例:CodePen Demo

                            【讨论】:

                            • 由于绝对定位,此解决方案将在打开引导模式时将页脚栏向右移动!
                            【解决方案24】:

                            使用flexbox 是我从CSS-tricks 的人那里找到的最简单的方法。这是真正的粘性页脚,它在内容小于页面的 100% 且大于页面的 100% 时起作用:

                            <body>
                              <div class="content">
                              content
                            </div>
                            <footer></footer>
                            </body>
                            

                            还有 CSS:

                            html {
                              height: 100%;
                            }
                            body {
                              min-height: 100%;
                              display: flex;
                              flex-direction: column;
                            }
                            .content {
                              flex: 1;
                            }
                            

                            请注意,这是与引导程序无关的,因此它可以与引导程序一起使用,也可以在没有引导程序的情况下使用。

                            【讨论】:

                              【解决方案25】:

                              您可以简单地尝试在页脚导航栏上添加一个类:

                              navbar-fixed-bottom
                              

                              然后像这样创建一个名为 custom.cssbody 填充的 CSS..

                              body { padding-bottom: 70px; }
                              

                              【讨论】:

                                【解决方案26】:

                                HTML

                                <footer class="footer navbar-fixed-bottom">
                                      <div class="container">
                                        <span class="text-muted">Place sticky footer content here.</span>
                                      </div>
                                    </footer>
                                

                                CSS

                                .footer {
                                    position: fixed;
                                    bottom: 0;
                                }
                                

                                【讨论】:

                                • 您好,欢迎来到 SO!虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。请阅读tourHow do I write a good answer? 另外,您是否检查过这些解决方案在该问题的其他 25 个解决方案中不存在?
                                猜你喜欢
                                • 2013-05-25
                                • 1970-01-01
                                • 1970-01-01
                                • 2014-07-30
                                • 2014-09-09
                                • 2014-03-08
                                • 1970-01-01
                                • 2023-03-09
                                • 2012-07-18
                                相关资源
                                最近更新 更多