简体   繁体   中英

How to make the position sticky to the screen

I am making a horizontal website which has a sticky top nav with a side bar which displays the name of page user is viewing. I want to make the side bar stick to the screen when the user reaches the desired page. Help would be much appreciated.

link to the pen
https://codepen.io/vishal2801/pen/ExZJOPK

Thanks in Advance.

Give your side bar class the following css:

<div class="sidebar">
    Content here
</div>

<style>
.sidebar {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1020;
}
</style>

change in css{position: fixed} For more info, https://www.w3schools.com/css/css_positioning.asp

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