【问题标题】:Sticky footer and content with 100% height粘性页脚和 100% 高度的内容
【发布时间】:2015-05-12 21:21:02
【问题描述】:

我想要一个带有粘性页脚的页面,它的滚动条不与页眉重叠,只有正文。就像我在this fiddle 中所做的那样。但现在我希望内容(虚线框)具有 100% 的主体高度。

html

<div class="navbar navbar-inverse navbar-fixed-top"></div>
<div class="container">
   <div class="content-container">
      <div class="my_content">Full height ??</div>
      <div class="push"></div>
   </div>
   <div class="footer"></div>
</div>

css

html,
    body {
        height: 100%;
        overflow: hidden;
    }

    body {
        padding-top: 50px;
    }

    .container {
        overflow-y: auto;
        overflow-x: hidden;
        height: 100%;
    }

    .content-container {
        padding-right: 15px;
        padding-left: 15px;
        margin-right: auto;
        margin-left: auto;
        position: relative;
        padding-top: 15px;
        padding-bottom: 15px;
        min-height: 100%;
        margin-bottom: -60px;
    }

    .footer {
        position: relative;
        width: 100%;
        background-color: red;
    }

    .footer,
    .push {
        height: 60px;
    }

    .my_content {
        border: 1px dotted;
        width: 100%;
        height: 100%;
        min-height: 200px;
        min-width: 300px;
    }

您可以建议使用任何其他模板来使用粘性页脚。

【问题讨论】:

    标签: html css sticky-footer


    【解决方案1】:

    您可以将.my_content 设置为视口高度的 100% 减去页面上其他元素的高度和(垂直)填充(即页眉高度、页脚高度、.content-container 上的顶部和底部填充),如下所示:

    .my_content {
      min-height: calc(100vh - 140px);
    }
    

    DEMO

    如果您的页眉和页脚具有可变高度,这将不起作用。

    【讨论】:

      【解决方案2】:

      将此示例用于不与页眉重叠的粘性页脚

      http://jsfiddle.net/0dbg9ko2/12/

      .footer {
      position: fixed;
      bottom:0;
      left:0;
      background-color: red;
      }
      

      我可以在 html 中进行一些更改

      【讨论】:

      • 滚动条出现时位于页脚下方
      • 不,我不想要固定页脚。我想要像我的小提琴一样的页脚。我只想让内容达到身体 100% 的高度
      • 是的,虽然这个答案提供了一个将页脚粘在视口底部的解决方案,但它不处理任何高度为 100% 的内容的要求。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 2012-02-25
      • 2013-03-18
      • 2015-01-30
      • 2014-09-20
      • 2016-01-04
      相关资源
      最近更新 更多