在Bootstrap 4中修复页脚?

时间:2018-08-14 02:14:58

标签: javascript jquery css html5 bootstrap-4

我正在开发的网站的页脚有问题。主页上有一个活跃的轮播。页脚在某些时候会稍微向上移动,在其下方留出空间。这可以为页脚做出贡献吗?我希望页脚处于固定/固定位置。任何帮助或想法,我们将不胜感激。谢谢!

enter image description here

这是下面的HTML标记:

<footer class="bg-info">
        
            <div class="container-fluid">
            <div class="row">
            <div class="col-md-4">
              <div><img src="images/Heart_n_hands.png" class="float-left" alt="logo" style="width:100px;">
            <span class="font-weight-bold">Our Neighbor Association</span> <br>
              <span>&copy; Copyright 2018</span>
              </div>
            </div>
            <div class="col-md-4">
             <address class="font-weight-bold">1200 W Smithfeld Avenue Somewhereville, MI 48326 <br> (888)-555-1234</address>
            </div>

          <div class="col-md-4">
              <span class="font-weight-bold">Sign up for Updates!</span>
              <form action="#" method="post">
                <div class="form-control bg-light">
                <label><small class="font-weight-bold">E-Mail:
                <input type="text" name="eMail" id="eMail" autocomplete="email" placeholder="Enter you E-Mail!" pattern="" required>
                </small></label>
                <input class="btn btn-primary btn-sm" type="submit" name="submit" id="submit" value="Subscribe">
                </div>
              </form>
          </div>
      </div>
      </div>
      </footer>

4 个答案:

答案 0 :(得分:1)

footer 标记中使用void MyClass::makeRequest() { ApiRequest* apiRequest = new ApiRequest(this); apiRequest->makeRequest(); } void MyClass::onApiRequestFinished() { // do my stuff } ... ApiRequest::ApiRequest(MyClass *cls) : m_cls(cls) { connect(this, &ApiRequest::requestFinished, this, &ApiRequest::finished); } void ApiRequest::finished() { m_cls->onApiRequestFinished(); delete this; } 类。

navbar navbar-fixed-bottom

答案 1 :(得分:0)

在Bootstrap 4中提供的用于粘贴页脚的解决方案是sticky footer

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
  /* Margin bottom by footer height */
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 60px;
  /* Set the fixed height of the footer here */
  line-height: 60px;
  /* Vertically center the text there */
  background-color: #f5f5f5;
  /* Not required */
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">


<main role="main" class="container">
  <h1 class="mt-5">Sticky footer</h1>
  <p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS.</p>
  <p>Use <a href="http://getbootstrap.com/docs/4.1/examples/sticky-footer-navbar">the sticky footer with a fixed navbar</a> if need be, too.</p>
</main>

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

如果您想要一种解决方案,当页面较短时保持页脚不放,但保持在较长页面下方(不固定),则可以使用flexbox。它还具有巨大优势,页脚无需在此处具有固定高度:

html {
  position: relative;
  min-height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex-grow: 1;
}

footer {
  flex-grow: 0;
  padding: 15px 0;
  display: block;
  background-color: #f5f5f5;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">


<main role="main" class="container">
  <h1 class="mt-5">Sticky footer</h1>
  <p class="lead">This one has the advantage you don't need to set a fixed height for footer (which would need to be the <code>&lt;body></code>'s bottom margin).</p>
</main>

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

答案 2 :(得分:0)

对于固定页脚,必须在HTML和CSS代码中使用此代码

body,html{
   height:100%;
}

.main{
height:auto;
min-height:100%;
}
<div class="main">
<h1>your contents here</h1>
</div>




<footer class="bg-info">
        
            <div class="container-fluid">
            <div class="row">
            <div class="col-md-4">
              <div><img src="images/Heart_n_hands.png" class="float-left" alt="logo" style="width:100px;">
            <span class="font-weight-bold">Our Neighbor Association</span> <br>
              <span>&copy; Copyright 2018</span>
              </div>
            </div>
            <div class="col-md-4">
             <address class="font-weight-bold">1200 W Smithfeld Avenue Somewhereville, MI 48326 <br> (888)-555-1234</address>
            </div>

          <div class="col-md-4">
              <span class="font-weight-bold">Sign up for Updates!</span>
              <form action="#" method="post">
                <div class="form-control bg-light">
                <label><small class="font-weight-bold">E-Mail:
                <input type="text" name="eMail" id="eMail" autocomplete="email" placeholder="Enter you E-Mail!" pattern="" required>
                </small></label>
                <input class="btn btn-primary btn-sm" type="submit" name="submit" id="submit" value="Subscribe">
                </div>
              </form>
          </div>
      </div>
      </div>
      </footer>

您必须包含两个部分:1:主要部分; 2:页脚 页脚不应位于main内部

答案 3 :(得分:0)

使用Bootstrap 4中的d-flex,这是我的代码

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<html>
    <style>
        html,body{
            height:100%;
        }
    </style>
    <body class="d-flex flex-column">
        <div class="flex-fill">
        (main div) i fill the black space
        </div>
        <footer class="mt-auto bg-info">Footer always down,at any height</footer>
    </body>
</html>

首先,正文和html以100%的高度填充页面。
然后,“ d-flex flex-column”类主体将在垂直方向上排列所有元素。
使用“ mt-auto”使页脚停留在底部。
最后,将您的主容器“灵活填充”,这样容器将填满空白空间。