How to keep the header static, always on top while scrolling?

前端 未结 8 812
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 08:15

How would I go about keeping my header from scrolling with the rest of the page? I thought about utilizing frame-sets and iframes, jus

8条回答
  •  情歌与酒
    2020-12-02 08:49

    After looking through all the answers, I found a slightly different way with minimum CSS and no JS, only the height of the header needs to be set correctly in #content, in this case 60px

    CSS:

    #header {
      position: fixed;
      width: 100%;
      top: 0;
      z-index: 10;
    }
    #content {
      margin-top: 60px;
      z-index:1;
    }
    

    HTML:

    
      
      

提交回复
热议问题