【问题标题】:How to display the page part after fixing the header and the footer固定页眉和页脚后如何显示页面部分
【发布时间】:2018-10-13 02:30:08
【问题描述】:

我想通过三个部分来显示我的网站:页眉、页面和页脚。现在我可以修复我的页眉和页脚,但是页眉屏蔽了页面的一部分并且页面不会放下我的页脚(我的页面的某些内容显示在我的页脚后面)

我的模板代码:

<div class="fixed-header">
  <...>
</div>

<div class="page">
  <...>
</div>

<div class="fixed-footer">
  <...>
</div> 

我的 CSS 是:

.fixed-header {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2;
  width: 100%  !important;
}

.footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    color: white;
    text-align: center;
}

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: html css header footer


    【解决方案1】:

    在 .page 的顶部和底部添加填充

    .page {
      padding-top: x // height of header
      padding-bottom: x // height of footer
    }
    

    .fixed-header {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 2;
      background: red;
      width: 100% !important;
      height: 20px;
    }
    
    .fixed-footer {
      background: blue;
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      color: white;
      text-align: center;
      height: 20px;
    }
    
    .page {
      margin: 20px 0;
      background: pink;
      width: 100px;
    }
    
    @media (max-width: 767px) {
      .fixed-header, .fixed-footer {
        height: 40px;
      }
      
    .page {
      margin: 40px 0;
      }
    }
    <div class="fixed-header">
      <...>
    </div>
    
    <div class="page">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi odio, est rerum quod nisi ipsam laboriosam quam eius doloremque exercitationem. Laboriosam aut consequatur atque natus beatae explicabo sunt. Quam, labore.
      
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi odio, est rerum quod nisi ipsam laboriosam quam eius doloremque exercitationem. Laboriosam aut consequatur atque natus beatae explicabo sunt. Quam, labore.
    </div>
    
    <div class="fixed-footer">
      <...>
    </div>

    【讨论】:

    • 它有效但不是很完美。因为页眉或页脚的高度随屏幕大小而变化。任何解决方案都可以针对不同尺寸的屏幕调整填充。
    • 你能展示一些真实的代码吗,因为它的结构很难这样说。
    • 您可以针对不同的屏幕尺寸使用媒体查询。
    • 查看我刚刚插入的sn-p。
    猜你喜欢
    • 2023-03-17
    • 2014-11-05
    • 2016-12-18
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    • 2015-02-02
    • 2016-06-25
    相关资源
    最近更新 更多