繁体   English   中英

使页脚停留在页面底部(不固定到底部)

[英]Make footer stay at bottom of page (not fixed to bottom)

我正在尝试仅使网站上具有主体内容类别为“ .interior-health-main”的页面的页脚位于页面底部。 我希望它在绝对底部,当前,如果您在大屏幕上查看我的某些页面,则在页脚后会看到一堆空白。 我想摆脱这个。

我已经研究了好几个小时,并尝试了许多事情,首先,我打算将整个网站的页脚置于页面底部的静态位置,但是将页脚的CSS设置为位置:与我的其他元素绝对冲突主页,这就是为什么我只想要它在“ .interior-health-main”上。 如果可以仅更改这些页面上的页脚,请告诉我,我真的不希望通过将整个正文设置为position:relative来解决此问题。 它只是弄乱了我的主页。

这是页脚后面的空白处的外观示例http://codepen.io/aahmed2/full/KgWNYL/

<p class="nav">This is a Navigation Bar</p>
<div class="interior-health-main">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="/index.asp">Home</a></li>
            <li><a href="/health-resources.asp">Health Resources</a></li>
            <li class="active">Sample Short Page</li>
        </ol>
    <h2>Sample Short Page</h2>



    </div>
</div>

<div class="footer">
  <div class="container">
    <div class="row">
      <div class="col-sm-4">
        <h4>Contact Us</h4>
        <p>414 Hardin Hall<br> 3310 Holdredge St<br> Lincoln, NE 68583<br> (402) 472-7363</p>
        <div class="affiliates">
          <a href="http://www.unl.edu/"><img class="wordmark" src="../_logos/wordmark.svg" alt="University of Nebraska-Lincoln Wordmark"></a>
          <a href="http://extension.unl.edu/"><img class="extension" src="../_logos/n-extension-rev.svg" alt="Nebraska Extension Logo"></a>
        </div>
      </div>

      <div class="col-sm-4">
        <h4>Quick Links</h4>
        <p><a href="#">Human Health</a></p>
        <div class="line"></div>
        <p><a href="/resources/pet-diseases.asp">Pet Diseases</a></p>
        <div class="line"></div>
        <p><a href="/resources/livestock-disease.asp">Livestock Diseases</a></p>
        <div class="line"></div>
        <p><a href="/resources/events.asp">Events</a></p>
        <div class="line"></div>
      </div>

      <div class="col-sm-4">
        <h4>Attention</h4>
        <p>All information on this site is intended for informational use only. Contact your doctor or veterinarian for health concerns.</p><br>
        <h5><a class="partner" href="#">Partners &amp Stakeholders</a></h5>

      </div>
    </div>

    <div class="copyright">
      <div class="col-xs-9">
        <h6>© 2016 Nebraska One Health. <a href="/sitemap.asp">Site Map.</a></h6>
      </div>

      <div class="col-xs-3">
        <a href="#"><img class="social  pull-right" src="../_logos/twitter-logo-button.svg" alt="twitter icon"></a>
        <a href="https://www.facebook.com/nebraskaonehealthresources/"><img class="social  pull-right" src="../_logos/facebook-logo-button.svg" alt="facebook icon"></a>
      </div>
    </div>
  </div>
</div>

这是我的CSS

.nav {
  text-align: center;
  padding: 25px 0;
  background-color: #c1c0be;
  color: #fff;
  position: fixed;
  width: 100%;
  z-index: 2;
}

.interior-health-main {
  padding-top: 80px;
  padding-bottom: 20px;
}

@media (max-width: 479px) {
  .interior-health-main {
    padding-top: 50px;
  }
}

.footer {
  background: #333332;
  border-top: 9px solid #ffffff;
  color: #fff;
  padding-top: 35px;
  padding-bottom: 35px;
}

您可以像在此处一样将页脚放置在绝对位置

https://getbootstrap.com/examples/sticky-footer/

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  /* background-color: #f5f5f5; */
}

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

尝试时如何冲突? 用您的工作更新您的帖子?

我将您的页面(不包含页脚)包装到.page-wrap div中,然后编辑您的codePen代码,然后将这段代码添加到您的CSS中

html, body {
  height: 100%;
}
.page-wrap {
  min-height: 100%;
  /* equal to footer height (with margin and border) */
  margin-bottom: -299px ; 
}
.page-wrap:after {
  content: "";
  display: block;
}
.footer, .page-wrap:after {
  /* page-wrap after content must be the same height as footer */
    height: 299px; 
}

演示版

请参考此问题以找到您的解决方案。

我将上述链接中的一种解决方案应用于您的代码。

将代码包装在#holder div中。

添加以下CSS:

html,body{
height: 100%
}

#holder{
min-height: 100%;
position:relative;
}

.footer {
background: #333332;
border-top: 9px solid #ffffff;
color: #fff;
padding-top: 35px;
padding-bottom: 35px;
height: 300px; 
width:100%;
position: absolute;
left: 0;
bottom: 0; 
}

.interior-health-main {
padding-top: 80px;
padding-bottom: 300px;    /* height of footer */
}

这是工作的小提琴: https : //jsfiddle.net/DTcHh/25475/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM