Hide scrollable content behind transparent fixed position divs when scrolling the page?

后端 未结 10 1058
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 09:16

I have a div called header that is set up with a fixed position. The problem is when I scroll the page the content of the page shows up behind the header (the header is tran

10条回答
  •  北海茫月
    2020-12-01 10:19

    Just coming to this late, but in case anyone else runs across this in the future, here's your fix.

    Your CSS Code:

    .wrapper {
        width:100%;
        position:fixed;
        z-index:10;
        background:inherit;
    }
    
    .bottom-wrapper {
        width:100%;
        padding-top:92px;
        z-index:5;
        overflow:auto;
    }
    

    Your HTML:

    ...your header here...
    ...your main content here...

    This will provide you with a header that cleanly matches your site, and floats at the top. The main content will scroll free of the header, and disappear when it passes the header. Your .bottom-wrapper padding-top should be the height of your header wrapper's content.

    Cheers!

提交回复
热议问题