
- HTML中文网
- 联系QQ:88526
- QQ交流群
- 微信公众号

background-attachment属性
含义:
background-attachment属性用于设置背景图像是否固定或者随着页面的其余部分滚动
浏览器支持:
| 属性 | ![]() | ![]() | ![]() | ![]() | ![]() |
|---|---|---|---|---|---|
| background-attachment | 4.0 | 1.0 | 1.0 | 1.0 | 3.5 |
注意: Internet Explorer 8和更早版本的浏览器不支持多个背景图像在一个元素
CSS语法:
background-attachment:scroll |fixed |inherit;
属性值:
| 值 | 说明 |
| scroll | 背景图片随页面的其余部分滚动,默认值 |
| fixed | 背景图像是固定的 |
| inherit | 指定background-attachment的设置应该从父元素继承 |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
body{
width:150px;
height: 80px;
background-image:url("images/logo.png");
background-attachment:fixed;
background-repeat: no-repeat;
}
div{
height: 2000px;
}
</style>
<div></div>
</body>
</html>点击 "运行实例" 按钮查看在线实例
效果图:

不管页面怎么向下滚动,图片的位置固定那不动
推荐手册