【问题标题】:How to create bootstrap footer at the end of page (NOT VISIBLE AT TOP OF PAGE)?如何在页面末尾创建引导页脚(在页面顶部不可见)?
【发布时间】:2021-09-09 22:39:34
【问题描述】:

我有一个网站,其中一些页面有很多元素(存在滚动),而其他页面只有很少的元素(不存在滚动)。我想要做的是让我的页脚始终位于页面底部,无论该页面有多大或多小。

我使用的引导页脚如下:

<footer class="text-center text-white bg-dark text-center">

    <!-- Section: Links  -->
    <section class="">
        
      <div class="container text-center text-md-start mt-5">
        <!-- Grid row -->
        <div class="row mt-3">
          <!-- Grid column -->
          <div class="col-md-3 col-lg-4 col-xl-3 mx-auto mb-4">
            <!-- Content -->
            <h6 class="text-uppercase fw-bold">Sun Dance Services</h6>
            <hr
                class="mb-4 mt-0 d-inline-block mx-auto"
                style="width: 60px; background-color: #7c4dff; height: 2px"
                />
            <p>
              Here you can use rows and columns to organize your footer
              content. Lorem ipsum dolor sit amet, consectetur adipisicing
              elit.
            </p>
          </div>

          <!-- Grid column -->
          <div class="col-md-2 col-lg-2 col-xl-2 mx-auto mb-4">
            <!-- Links -->
            <h6 class="text-uppercase fw-bold">Countries</h6>
            <hr
                class="mb-4 mt-0 d-inline-block mx-auto"
                style="width: 60px; background-color: #7c4dff; height: 2px"
                />
            <p><i class="fas fa-home mr-3"></i>United Kingdom</p>
            <p><i class="fas fa-envelope mr-3"></i>Cyprus</p>
            <p><i class="fas fa-phone mr-3"></i>Ireland</p>
            <p><i class="fas fa-print mr-3"></i>United States</p>
          </div>

          <!-- Grid column -->
          <div class="col-md-3 col-lg-2 col-xl-2 mx-auto mb-4">
            <!-- Links -->
            <h6 class="text-uppercase fw-bold">Useful links</h6>
            <hr
                class="mb-4 mt-0 d-inline-block mx-auto"
                style="width: 60px; background-color: #7c4dff; height: 2px"
                />
            <p>
              <%= link_to 'Home Page', root_path, class:"text-white" %>
            </p>
            <p>
              <%= link_to 'About Us', home_about_path, class:"text-white" %>
            </p>
            <p>
              <%= link_to 'Products & Services', home_products_path, class:"text-white" %>
            </p>
          </div>

          <!-- Grid column -->
          <div class="col-md-4 col-lg-3 col-xl-3 mx-auto mb-md-0 mb-4">
            <!-- Links -->
            <h6 class="text-uppercase fw-bold">Contact</h6>
            <hr
                class="mb-4 mt-0 d-inline-block mx-auto"
                style="width: 60px; background-color: #7c4dff; height: 2px"
                />
            <p><i class="fas fa-home mr-3"></i> New York, NY 10012, US</p>
            <p><i class="fas fa-envelope mr-3"></i> info@example.com</p>
            <p><i class="fas fa-phone mr-3"></i> + 01 234 567 88</p>
            <p><i class="fas fa-print mr-3"></i> + 01 234 567 89</p>
          </div>
        </div>
      </div>
    </section>

    <!-- Copyright -->
    <div
         class="text-center p-3"
         style="background-color: rgba(0, 0, 0, 0.2)"
         >
      © 2021 Copyright:
      <a class="text-white" href="https://mdbootstrap.com/"
         >Sun Dance Services</a
        >
    </div>

</footer>

我尝试了&lt;footer class="text-center text-white bg-dark text-center fixed-bottom"&gt;,它仅针对小内容页面解决了这个问题。它将页脚设置在最低位置(此处不存在滚动)。查看屏幕截图 1!

但是,当页面很大时,有两个问题:

  • 页脚始终出现在页面底部(当滚动位置位于页面顶部时,页脚出现)。
  • 页脚隐藏位于末尾的元素(请参阅下面的屏幕截图 2)。


我想做什么:

  1. 无论内容大小,页脚都应放在页面末尾。
  2. 当滚动不在页面底部时隐藏页脚。
  3. 我不想固定页脚。
  4. 如果我使用普通的 bootsrap 而不是 CSS,我会更喜欢。

【问题讨论】:

  • 在这里您可以找到解决问题的方法 - stackoverflow.com/questions/643879/…
  • 这个 BS-5 stackoverflow.com/a/40854221/1011984 的答案列出了如何将 d-flex flex-column min-vh-100 应用到正文标签,然后将 mt-auto 应用到页脚。
  • @LovekeshKumar 对我不起作用。我也不想使用 CSS。
  • @RichDeBourke 完美运行。这就是我想要的!非常感谢。你能把我的问题标记为重复吗?

标签: html bootstrap-5


【解决方案1】:

你可以为body标签设置最小高度,这样无论body的高度如何,你都会强制页脚位于底部

【讨论】:

  • 你的意思是这样的:&lt;body style="min-height: 100px"&gt;。如果,那么无论是否在页脚元素上使用fixed-bottom,这都不起作用
  • 试试 vh 值而不是 px!
猜你喜欢
  • 1970-01-01
  • 2023-03-15
  • 2016-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 1970-01-01
相关资源
最近更新 更多