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

前端 未结 8 826
被撕碎了的回忆
被撕碎了的回忆 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

    Use position: fixed on the div that contains your header, with something like

    #header {
      position: fixed;
    }
    
    #content {
      margin-top: 100px;
    }
    

    In this example, when #content starts off 100px below #header, but as the user scrolls, #header stays in place. Of course it goes without saying that you'll want to make sure #header has a background so that its content will actually be visible when the two divs overlap. Have a look at the position property here: http://reference.sitepoint.com/css/position

提交回复
热议问题