CSSbackground-attachment是css软件的一种属性。属性设置背景图像是否固定或者随着页面的其余部分滚动,所有浏览器都支持。
CSSbackground-attachment定义和用法
background-attachment属性设置背景图像是否固定或者随着页面的其余部分滚动。
默认值:
scroll
继承性:
no
版本:
CSS1
JavaScript语法:
object.style.backgroundAttachment="fixed"
如何设置固定的背景图像:
body{background-image:url(bgimage.gif);background-attachment:fixed;}
浏览器支持编辑
所有浏览器都支持background-attachment属性。
注释:任何版本的InternetExplorer(包括IE8)都不支持属性值"inherit"。
CSSbackground-attachment可能的值
值
描述
scroll
默认值。背景图像会随着页面其余部分的滚动而移动。
fixed
当页面的其余部分滚动时,背景图像不会移动。
inherit
规定应该从父元素继承background-attachment属性的设置
TIY实例编辑
如何设置固定的背景图像
本例演示如何设置固定的背景图像。图像不会随着页面的其他部分滚动。
<html>
<head>
<styletype="text/css">
body
{
background-image:url(/i/eg_bg_02.gif);
background-repeat:no-repeat;
background-attachment:fixed
}
1
</style>
</head>
<body>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
</body>
</html>
总之,CSSbackground-attachment给大家简单的介绍了一些,希望大家多看看。