【问题标题】:Sticky footer that extends when at website-bottom and scrolling further在网站底部并进一步滚动时扩展的粘性页脚
【发布时间】:2017-01-09 08:51:59
【问题描述】:

我有一个非常好的想法,可以让我的项目更漂亮。
我希望页脚是标准的,如下图所示:

当我现在进一步向下滚动时,页脚向上并在下面显示所有内容,例如“Impressum”和“Contact”。
我在互联网上搜索了各种解决方案,但找不到合适的解决方案。
我希望你能帮助我。

我的页脚代码:

HTML:

<footer>
    <div class="footer">
            <p class="footer-text"><a href="{{ path('homepage') }}">OneClick</a></p>
    </div>
</footer>

CSS:

.footer {
    position: fixed;
    left: 0px;
    right: 0px;
    bottom: 0px;
    width: 100%;
    padding-top: 10px;
    background: #F28724;
    font-size: 1.3em;
}
.footer-text {
    color: #3a3a3a;
}
.footer-text > a {
    color: #3a3a3a;
    display: table;
    text-align: center;
    margin-right: auto;
    margin-left: auto;
}

【问题讨论】:

  • 图片在哪里?
  • 如果有完整的 HTML 代码或jsfiddle.net 示例,那就太好了
  • 不幸的是,我在我的项目中使用了 symfony,而将其放入 jsfiddle 是不可能的,我在这里发布的内容应该足以显示我的问题

标签: html css


【解决方案1】:

将绝对位置分配给页脚和底部:0;

【讨论】:

  • 页脚应该保持粘性页脚,所以当页面内容太多时我必须滚动。页脚一直是图片中的小页脚,当我到达页面底部时,页脚会进一步滚动,并且印象中的内容会显示 PS:如果它会如此简单的修复,我会自己弄清楚
  • 应该是评论
  • Inzimam,恐怕我不知道你想说什么
【解决方案2】:

你可以试试这个使用 CSS 的 calc 函数的解决方案(阅读更多:http://www.w3schools.com/cssref/func_calc.asp),但是,据报道这不支持 IE8,我相信 Chrome 会运行良好

HTML:

<header>
  <h1>Header</h1>
</header>

<main>
  <content>
    <p>content</p>
  </content>

  <footer>
    <p>Footer</p>
  </footer>
</main>

CSS:

html,
body {
    margin:0;
    padding:0;
    min-height:100vh;
}

header {
    background: LightSlateGray;
  height: 100px;
  line-height: 100px;
    padding: 0 10px;
}
 header h1 { margin: 0; }

main { height: auto; min-height: calc(100vh - 100px); }
content, footer { display: inline-block; width: 100%; }

content { height: auto; min-height: calc(100vh - 200px); background:lightblue; }
footer {
    height:100px;           /* Height of the footer */
    background:#6cf;
}

演示:https://jsfiddle.net/89ucrec5/4/

【讨论】:

    【解决方案3】:

    $(function() {
      $(window).scroll(function() {
        if ($(document).scrollTop() > 100) {
          $('.footerContent').slideDown(650);
        } else if ($(document).scrollTop() < 100) {
          $('.footerContent').fadeOut(500);
        }
      });
    })
    body,
    html {
      height: 1000px;
    }
    .footer {
      position: fixed;
      z-index: 99;
      left: 0px;
      right: 0px;
      bottom: 0px;
      width: 100%;
      padding-top: 10px;
      background: #F28724;
      font-size: 1.3em;
    }
    .footer-text {
      color: #3a3a3a;
    }
    .footer-text > a {
      color: #3a3a3a;
      display: table;
      text-align: center;
      margin-right: auto;
      margin-left: auto;
    }
    .footerContent {
      height: 150px;
      position: fixed;
      bottom: 0;
      width: 100%;
      left: 0;
      background: #F28724;
      display: none;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <div class="footer">
      <p class="footer-text"><a href="{{ path('homepage') }}">OneClick</a>
      </p>
    </div>
    
    <div class="footerContent">
      <p>Contact ...
        <p>
    </div>

    【讨论】:

    • thx,乍一看它就像一个魅力,但是当你滚动一下时它会出现一些错误,也许我能够修复它们,不太确定,我会尝试
    • 玩一下,告诉我!
    • @BenjaminPössenberger - 我刚刚优化了我的代码并做了一些改动。
    • 我发现它在我的大多数网站上都不起作用,而且我无法修复它在我的网站上存在的错误,它仍然是一个非常好的解决方案,我希望它可以帮助其他人: D
    • 这个改变让它更漂亮了,但现在它在更少的网站上工作,我必须用不同的风格来放置我的印象/联系人
    猜你喜欢
    • 2013-07-27
    • 1970-01-01
    • 2017-03-26
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多