使页面的第一部分停留在顶部

阿里雷扎

在我的页面上有两个部分,分别是标题div和内容div。我希望JS或jquery解决方案将标题部分放在顶部,以便用户滚动内容部分时可以交叉并覆盖标题部分。

的HTML:

<div id="header">
    <h3>I'd like to stick here at the background, please! </h3>
</div>
<div id="content">
    <h3>I'd like to cross over the header when user scrolls.</h3>
</div>

http://jsfiddle.net/KNh46/

奥尔奇克

更新:误解了,所以您希望内容滚动到标题上方,而不是下方然后应该是这样的:

#header {
    position: fixed;
    height: 100px;
    top: 0;
    z-index: 100;
}

#content {
    position: relative;
    margin-top: 100px;
    z-index: 101;
}

在此处查看示例:http : //jsfiddle.net/aorcsik/v7zav/


如果标题是固定高度,请说100px,然后:

#header {
    position: fixed;
    height: 100px;
    top: 0;
}

#content {
    margin-top: 100px;
}

这样,当滚动到顶部时,标题不会覆盖内容,但是当您开始向下滚动时,它将覆盖内容。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章