CSS background-attachment 属性
CSS background-attachment 属性决定背景图像的位置是在视口内固定,或者随着包含它的区块滚动。
实例
如何设置固定的背景图像:
<html><head><style type="text/css">body{background-image:url(/images/img_tree.gif);background-repeat:no-repeat;background-attachment:fixed}</style></head><body><p>图像不会随页面的其余部分滚动。</p><p>A</p><p>B</p><p>C</p><p>D</p><p>E</p><p>F</p><p>G</p><p>H</p><p>I</p><p>J</p><p>K</p><p>L</p><p>M</p><p>N</p><p>O</p><p>P</p><p>Q</p><p>R</p><p>S</p><p>T</p><p>W</p><p>X</p><p>Y</p><p>Z</p></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 属性 | |||||
|---|---|---|---|---|---|
| background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
定义和用法
background-attachment 属性设置背景图像是否固定或者随着页面的其余部分滚动。
| 默认值: | scroll |
|---|---|
| 继承性: | no |
| 版本: | CSS1 |
| JavaScript 语法: | object.style.backgroundAttachment="fixed" |
可能的值
| 值 | 描述 |
|---|---|
| scroll | 默认值。背景图像会随着页面其余部分的滚动而移动。 |
| fixed | 当页面的其余部分滚动时,背景图像不会移动。 |
| inherit | 规定应该从父元素继承 background-attachment 属性的设置。 |
相关页面
CSS 教程:CSS 背景