前端之家收集整理的这篇文章主要介绍了
css-根据页面滚动固定div ,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在为朋友开发一家商店,当用户在其后滚动时,我想修复“添加到购物车的DIV”.由于我远非CSS专家,因此我面临着问题.
我试图使用JS在div上添加“ position:fixed”,但是我不能这样做,因为div具有相对位置,并且对其进行更改会固定所有div元素的混乱
this is the link
这是我要固定的div(div ID是rightcol):

我也想让div在页脚之前停下来
提前致谢
最佳答案
使用此
属性可使div在滚动时保持粘性
position: -webkit-sticky;
position: sticky;
top: 0;

标头是您的网站也很粘.您可以使用相同的属性