CSS and JS, make div follows scroll

痞子三分冷 提交于 2020-02-25 06:49:06

问题


I have tried using position fixed but I just cannot seem to find out how to do it, I want my sidebar to stay fixed along the screen as the user scrolls, my sidebar element id is #displayside can someone please help me out and explain what I must do to have this fixed.

Please excuse me if this question is too obvious but I am just starting to code and I need help.

Thanks!

#displayside {
     width: 15%;
    /* margin-left: 25px; */
    float:right;
    text-align:center;
    padding:5px;
    margin:3px;
    background-image:url('/resources/images/htmlbg.jpeg');
   -moz-border-radius: 10px;
   -webkit-border-radius: 10px;
   border-radius: 10px; /* future proofing */
   -khtml-border-radius: 10px; /* for old Konqueror browsers */
   position: fixed;

回答1:


Use position:fixed

#displayside
{
 position:fixed;
}

and set top and left according to your requirement

as

#displayside
    {
     position:fixed;
     left:10px;
     top:10px;
    }


来源:https://stackoverflow.com/questions/11395201/css-and-js-make-div-follows-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!