html - 如何避开位置: fixed from staying on the screen when vertical scrolling?

标签 html css position

asked this question这对于使文本(顶部链接)在滚动后被迫向右移动非常有效。

问题出在页面上,当我垂直滚动时,即使向下滚动,顶部链接仍保留在页面顶部,因此它们显示在我的主要内容上方。

有什么方法可以强制文本向右移动但在垂直滚动时不移动?

这是我今天的 CSS:

#toplinks ul
{
    -moz-background-clip:border;
    -moz-background-inline-policy:continuous;
    -moz-background-origin:padding;
    background:transparent none repeat scroll 0 0;
    border:medium none;
    color:#2F6FAB;
    cursor:default;
    line-height:1.4em;
    list-style-image:none;
    list-style-position:outside;
    list-style-type:none;
    margin:0;
    padding:0 1em 0 1em;
    text-align:right;
    z-index:0;
    font-size: 85%;

    position:fixed;
    right:0;
}

最佳答案

我想你想要像 this 这样的东西.如果我错了,请纠正我。我编辑了 ptriek 的代码并修复了它,如果页面垂直滚动,粘性的东西不会移动,但如果页面水平滚动,粘性的东西会随着页面移动,保持其位置固定。

CSS代码是一样的:

#sticky
{
    background:red;
    position: fixed;
    top: 0px;
    right: 0px;
    width: 206px;
    padding: 0;
    font-size: 0.6875em;
}

p {
    width:1000px;
}

但 JavaScript 代码稍作修改:

$(window).scroll(function(event) {
    $("#sticky").css("margin-top", 0-$(document).scrollTop());
});

或者,这可以像 Aaron 所建议的那样在没有 JavaScript 的情况下完成。可以看到效果 here .

我希望它有用。

关于html - 如何避开位置: fixed from staying on the screen when vertical scrolling?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8590904/

相关文章:

html - 加载后 jQuery Mobile 页面调整大小可见

css - 分辨率较小,内容尽量适合

iphone - 如何在 Mobile Safari 中从 <input type "0"> 中删除 ="number"占位符?

html - 为什么当容器的图片内容高度发生变化时,容器的高度不适应?

javascript - 如何创建下拉汉堡菜单

jquery - 如何使我的元素在我的导航栏中流畅

css - IE8 与 IE8 兼容模式插入边框 CSS 问题

html - 获取底部 div 以保持低于位置绝对 div

r - 在 ggplot 中将 x 轴标签指向内

javascript - PhoneGap HTML5 播放器