✨6.background-attachment 属性设置背景图像是否固定或随着页面的其余部分滚动
- 语法:
background-attachment:scroll/fixed
background-attachment 属性的参数值:
| 参数 | 作用 |
|---|---|
scroll | 背景图随对象内容滚动 |
fixed | 背景图像固定 |
✨7.背景复合写法(简写)
为了简化背景属性的代码,我们可以将这些属性合并简写在同一个属性background中,从而节约代码量 当使用简写属性时,没有特定的书写顺序,一般习惯的顺序为:
background: 背景颜色 背景图地址 背景平铺 背景图像滚动 背景图片位置
如:background: transparent url("image.jpg") repeat-y fixed top ;
✨8.背景颜色透明度
CSS3为我们提供了背景颜色半透明的效果
background-color: rgba(0,0,0,0.3);
- 最后一个参数是
alpha透明度,取值范围0-1之间 - 我们习惯把0.3的0省略掉,写为
background: rgba(0,0,0,.3); - 注意:背景半透明是指盒子背景半透明,盒子里面的内容不受影响
- CSS3新增属性,是IE9+版本浏览器才支持的
- 但现在实际开发,我们不太关注兼容性写法,可放心使用
✨9.背景属性总结:
| 属性 | 作用 | 值 |
|---|---|---|
background-color | 背景颜色 | 预定义的颜色值 / 十六进制 / RGB代码 |
background-image | 背景图片 | url("图片路径") |
background-repeat | 是否平铺 | repeat / no-repeat / repeat-x / repeat-y |
background-position | 背景位置 | length / position(分别是x和y坐标) |
background-attachment | 背景附着 | scroll(背景滚动) / fixed(背景固定) |
| 背景简写 | 书写更简单 | 背景颜色 背景图片地址 背景平铺 背景滚动 背景位置 |
| 背景色半透明 | 背景颜色半透明 | background: rgba(0,0,0,0.5);(后面必须是4个值) |
💡注:背景图片:实际开发常见于logo或一些装饰性的小图片或超大图片,优点是非常便于控制(精灵图也是一种运用场景)