文章摘要
这篇文章介绍了如何使用CSS的`background-attachment: fixed`属性来实现背景图片固定在页面指定位置的效果,不会因滚动条而移动。通过代码示例展示了如何设置背景图片,具体代码如下:
```css
body {
background: url(bj.png) no-repeat;
background-size: 100%;
background-attachment: fixed;
}
```
此外,文章还提到可以通过修改颜色属性`background-color: #ff0000;`来改变背景颜色。
今天分享一篇关于background-attachment:fixed的实战示例,background-attachment:fixed可以让背景图片固定到一个位置,不会随滚动条滚动而变化。
下面我们就利用background-attachment:fixed给网站加上一个固定背景,效果如下:
利用background-attachment:fixed给网站加上一个固定背景
CSS效果截图
CSS代码:
body{
background: url(bj.png) no-repeat;
background-size: 100%;
background-attachment: fixed;
}
bj.png可以自己网上找,路径只要写对就行。
然后如果还需要背景颜色的可以这样修改:
background: url(bj.png) no-repeat #ff0000;
© 版权声明
文章版权归作者所有,未经允许请勿转载。