Html 固定页眉,页面滚动到页眉并隐藏

Html 固定页眉,页面滚动到页眉并隐藏,html,css,Html,Css,我有一个固定的页眉和页脚,高度为50px。但是,当我滚动页面时,页面内容与固定的页眉和页脚重叠。当页面滚动到页眉和页脚(前50px)时,如何隐藏页面 这只能在HTML/CSS中完成。如果需要JS或JQ来执行此操作,那么我将忘记执行此操作 CSS HTML 此内容应保持在顶部。 使用滚动条时,此内容不应移动。 此内容应放在底部。 例如,尝试向页脚添加值 bottom: 0; 检查这把小提琴: 编辑 或者可以为页面元素指定高度 .page { position: relative; displa

我有一个固定的页眉和页脚,高度为50px。但是,当我滚动页面时,页面内容与固定的页眉和页脚重叠。当页面滚动到页眉和页脚(前50px)时,如何隐藏页面

这只能在HTML/CSS中完成。如果需要JS或JQ来执行此操作,那么我将忘记执行此操作

CSS

HTML


此内容应保持在顶部。
使用滚动条时,此内容不应移动。
此内容应放在底部。

例如,尝试向页脚添加值

bottom: 0;
检查这把小提琴:

编辑

或者可以为页面元素指定高度

.page {
position: relative;
display:block;
height: 50px;
}

css


对于页眉,只需给页面内容留一个页边空白。对于页脚和页眉,为它们指定一个高于页面div的z索引,以确保其与内容重叠

     header {
   height: 50px;
   position:fixed;
    top:0px;
    left:0px;
    z-index:4;
    background-color:orange;
 }

 .page {
    margin-top:40px;

}



 .main {
   float: right;
   width: 740px;
 }

 footer {
     position: fixed;
    bottom: 0px;
   height: 50px;
    background-color:orange;
    z-index:4;
 }

我想你要找的是这个-

header {
  top: 0;
   height: 50px;
   position: fixed;
   display:block;             /* fill the width */
   z-index:2;                 /* z-index greater than .main */
   width:100%;                /* fill the width */
   background-color: white;   /* To make it opaque */
 }

 .page {
   position: relative;
 }

 .sidebar {
   top: 50px;
   float: left;
   position: fixed;
   width: 220px;
 }

 .main {
   margin-top: 50px;
   float: right;
   left: 220px;
   width: 740px;
   z-index:1;                /* z-index lesser than header and footer */
 }

  footer {
    position: fixed;
    height: 50px;
    bottom: 0;
    display:block; /* fill the width */
    z-index:2;  /* z-index greater than .main */
    width:100%;  /* fill the width */
    background-color: white; /* To make it opaque */
  }

请参见此处的示例-

此内容应位于顶部。-这可能无法解决问题,但最好是用
纠正输入错误。看看这是否解决了您的问题(它应该与页眉元素匹配)。这是一个输入错误,而不是在我的实际html上。元素保持不变,但是,main仍然覆盖页眉和页脚。它应该看起来像是在它下面滚动。我不确定我是否正确-但你是否尝试过使用z索引?我宁愿不设置固定的高度,因为屏幕较大的访问者会看到不同的页面。我宁愿让高度流动。只是最后一个,我没有主意:)你可以设置一个“最小高度”,这样你的元素就不会崩溃,如果添加更多内容,仍然可以扩展。
body, html {
    height: 100%;
    margin:0;
    padding:0;
}
header {
    top:0;
    height: 50px;
    position: fixed;
    left:0;
    right:0;
    background: #ccc;
    z-index:2;
}
.page {
    position: relative;
    background: #eee;
    z-index:1;
    height: 100%;
}
.sidebar {
    left:0;
    position: fixed;
    width: 220px;
    top:50px;
    bottom: 50px;
    background: #ddd;
    height: calc(100% - 100px);
}
.main {
    float: right;
    width: calc(100% - 220px);
    height: 100%;
    background: red;
    margin:50px 0;
}
footer {
    position: fixed;
    height: 50px;
    bottom:0;
    left:0;
    right:0;
    background: #aaa;
    z-index:2;
}
     header {
   height: 50px;
   position:fixed;
    top:0px;
    left:0px;
    z-index:4;
    background-color:orange;
 }

 .page {
    margin-top:40px;

}



 .main {
   float: right;
   width: 740px;
 }

 footer {
     position: fixed;
    bottom: 0px;
   height: 50px;
    background-color:orange;
    z-index:4;
 }
header {
  top: 0;
   height: 50px;
   position: fixed;
   display:block;             /* fill the width */
   z-index:2;                 /* z-index greater than .main */
   width:100%;                /* fill the width */
   background-color: white;   /* To make it opaque */
 }

 .page {
   position: relative;
 }

 .sidebar {
   top: 50px;
   float: left;
   position: fixed;
   width: 220px;
 }

 .main {
   margin-top: 50px;
   float: right;
   left: 220px;
   width: 740px;
   z-index:1;                /* z-index lesser than header and footer */
 }

  footer {
    position: fixed;
    height: 50px;
    bottom: 0;
    display:block; /* fill the width */
    z-index:2;  /* z-index greater than .main */
    width:100%;  /* fill the width */
    background-color: white; /* To make it opaque */
  }