【问题标题】:CSS and JS, make div follows scrollCSS和JS,让div跟随滚动
【发布时间】:2013-07-25 02:59:57
【问题描述】:

我尝试过使用固定位置,但我似乎不知道该怎么做,我希望我的侧边栏在用户滚动时沿着屏幕保持固定,我的侧边栏元素 ID 是 #displayside 有人可以帮我吗出来解释我必须做些什么来解决这个问题。

如果这个问题太明显,请见谅,但我刚刚开始编码,需要帮助。

谢谢!

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

【问题讨论】:

  • 固定位置确实可以实现您想要的。如果它不起作用,请发布一些代码,或者最好设置一个 JS Fiddle,否则我们完全是在盲目地工作。
  • 谢谢,我再看一遍,如果还是不行,我会发布 css。
  • 只是为了扩展,我如何让只有 1 个元素与滚动一起使用?所以我的主要内容是用固定的标题和东西滚动的。

标签: javascript css css-position


【解决方案1】:

使用position:fixed

#displayside
{
 position:fixed;
}

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

作为

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

【讨论】:

  • #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;??它不工作!
  • 谢谢,我错过了屏幕上的定位,现在可以了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-05
  • 2018-12-23
  • 1970-01-01
  • 1970-01-01
  • 2020-05-23
  • 1970-01-01
相关资源
最近更新 更多