简体   繁体   中英

How to keep the header at fixed position even while page is scrolling

I am trying to create a header which remains fixed at top but what happens is when i scroll down the page the header moves along with it while maintaining its position. My requirement is that the header shouldn't move with the page as we scroll down.

JS FIDDLE:https://jsfiddle.net/qa5d1ry0/

Note : Its just a dummy code of my layout and i have added random text in order to get the code working

Note : I have tried using position:absolute for header but the problem is that header don't get displayed as we scroll

Try to give position: fixed; to the header and remove the relative position from container.

.header {
    position: fixed;
} 

Try to add top:0px; after your position:fixed; for the header/heading div.

It's fixed for me. Try position: fixed . What browser are you using?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM