页脚不会停留在页面底部

时间:2019-01-28 18:05:40

标签: html css ruby-on-rails

enter image description here

页脚不会停留在页面底部。我在application.html.erb文件中渲染了一部分。我想知道是否是因为我在我的应用程序erb文件中有div容器外部渲染了页脚部分。

<html>
 <head>
 </head>

  <body>


    <%= render 'shared/navbar'  %>
    <%= render 'shared/message'  %>

    <!-- NOTIFICATIONS -->
    <% if current_user %>
    <input type="hidden" id="user_id" value="<%= current_user.id %>">
    <% end %>



   <div class="container">
    <%= yield %>
  </div>

  <%= render 'shared/footer' %>
  </body>
</html>


<footer class="section footer-classic context-dark bg-image" style="background: #2d3246;">
    <div class="container">
      <div class="row row-30">
        <div class="col-md-4 col-xl-5">
          <div class="pr-xl-4"><a class="brand" href="index.html"><img class="brand-logo-light" src="images/agency/logo-inverse-140x37.png" alt="" width="140" height="37" srcset="images/agency/logo-retina-inverse-280x74.png 2x"></a>
            <p>We are an award-winning creative agency, dedicated to the best result in web design, promotion, business consulting, and marketing.</p>
            <!-- Rights-->
            <p class="rights"><span>©  </span><span class="copyright-year">2019</span><span> </span><span style="color: red;">B</span><span>. </span><span>All Rights Reserved.</span></p>
          </div>
        </div>
        <div class="col-md-4">
          <h5>Contacts</h5>
          <dl class="contact-list">
            <dt>email:</dt>
            <dd><a href="info@budlyfe.com">info@b.com</a></dd>
          </dl>
        </div>
        <div class="col-md-4 col-xl-3">
          <h5>Links</h5>
          <ul class="nav-list">
            <li><a><%= link_to 'About', about_path %></a></li>
            <li><a><%= link_to 'FAQ', faq_path %></a></li>
            <li><a><%= link_to 'Contact', contact_path %></a></li>
          </ul>
        </div>
      </div>
    </div>
  </footer>

3 个答案:

答案 0 :(得分:2)

其他人所说的使用固定位置将起作用。如果您不想从流程中取出任何东西,则另一种选择是使用flex。只需将所有不包含页脚的内容包装在容器中。然后给body class像

body{
 width: 100%;
 min-height: 100vh;
 display: flex;
 flex-direction: column;
}
.container{
flex-grow: 1;
}

footer{
flex-grow: 0;
}

因此,主体至少为视口的高度。无论页脚多么高,它都必须是高的,并且无论容器中有多少东西,容器都将至少填充其余的空间,从而迫使页脚向下。如果有帮助,请使用Codepen Example

答案 1 :(得分:1)

您需要为页脚定义一个静态高度,并为底部定义一个固定位置,底部为0,像这样:

footer {
   position: fixed;
   height: XXX;
   bottom: 0;
   width: 100%;
}

答案 2 :(得分:0)

您是否尝试过添加CSS?

尝试这样的事情。

.footer-classic { 
   position: fixed;
   left:0;
   bottom:0;
   height: defineYourHeight;
   width:100%;
}
相关问题