CSS和JS,使div跟随滚动 [英] CSS and JS, make div follows scroll

查看:266
本文介绍了CSS和JS,使div跟随滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用固定位置,但是我似乎无法找出方法,我希望我的侧边栏在用户滚动时保持固定在屏幕上,我的侧边栏元素ID为 #displayside 有人可以帮我解决这个问题吗?

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.

谢谢!

#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;


推荐答案

使用 position:fixed

#displayside
{
 position:fixed;
}

并根据您的要求设置顶部和左侧

and set top and left according to your requirement

as

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

这篇关于CSS和JS,使div跟随滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆