【问题标题】:footer doesn't appear on bottom of page when using 100vh [duplicate]使用 100vh 时,页脚不会出现在页面底部 [重复]
【发布时间】:2021-05-30 01:58:19
【问题描述】:

说明:

我想使用以下 css 将我的网站构建成几个页面:

.page {
    height: 100vh;
}

我在网站上添加了几个页面,在最后一个页面上,我希望页脚出现在页面底部,例如

.page {
  height: 100vh;
  background-color: cyan;
}

footer {
  position: relative;
  width: 100%;
  height: 100px;
  bottom: 0;
  background-color: #000;
}
<div class="page">Page 1</div>
<div class="page">Page 2</div>
<div class="page">
  <footer></footer>
</div>

我的尝试:

  • 我尝试设置 position: absolute (of footer) 就像这个答案:css - footer doesn't go at bottom
  • 我还尝试在页脚周围放置一个包装器,高度为:100%;
  • 我还使用了 min-height: 100vh 而不是没有效果的 height

问题:

如何将页脚置于页面底部?

PS:我不知道这是否相关,但我使用的是 Firefox v. 85.0.2(64 位)

编辑:

我希望页脚在页面内,我使用这些页面来构建我的网站,并且页脚应该出现在最后一页的底部。

【问题讨论】:

    标签: html css alignment footer


    【解决方案1】:

    以下代码将解决您的问题:

    .page {
        margin: 0;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        background-color: cyan;
    }
    
    .spacer {
        flex: 1;
    }
    
    footer {
      width: 100%;
      height: 100px;
      background-color: #000;
    }
    <div class="page">Page 1</div>
    <div class="page">Page 2</div>
    <div class="page">Page 3
    <div class="spacer"></div>
    <footer></footer>
    </div>

    【讨论】:

    • 这可行,但我实际上希望页脚位于页面内部。
    • 我希望能够将元素定位在页面内,以概括我的问题
    • 答案已修改。
    猜你喜欢
    • 2017-02-07
    • 2018-08-11
    • 2020-10-03
    • 1970-01-01
    • 2016-02-25
    • 2015-05-09
    • 2020-04-04
    • 2014-11-17
    • 2020-02-11
    相关资源
    最近更新 更多