只需要在需要背景不跟着动的 div 里:
- div{
- background:url();
- background-attachment:fixed;
- }
加上 background-attachment:fixed; 就可以了, 兼容 IE6+
(相关课程推荐: CSS 视频教程 https://www.html.cn/css/ )
效果:
如果不加这个属性:
网上兼容 IE6 的方法:
- <script type="text/javascript">
- var scrollBackground = true;
- </script>
加一句 JS 就行了
background-attachment 属性设置背景图像是否固定或者随着页面的其余部分滚动.
值 | 描述 |
---|---|
scroll | 默认值。背景图像会随着页面其余部分的滚动而移动。 |
fixed | 当页面的其余部分滚动时,背景图像不会移动。 |
inherit | 规定应该从父元素继承 background-attachment 属性的设置。 |
本文来自 CSS 答疑 https://www.html.cn/qa/css3/ 栏目, 欢迎学习!
来源: http://www.css88.com/qa/css3/14373.html