一、背景颜色
background-color 一般默认是透明色(transparent)
二、背景图片
background-image : url(URL) 常用于logo或者按钮,而不是使用插入图片,背景图片优点是便于控制位置
1、背景平铺
background-repeat : repeat | no-repeat | repeat-x | repeat-y

2、背景图片的位置
background-position :x y ; 改变图片在背景中的位置

参数是方位名词
(1)如果指定的两个值都是方位名次,则两个值前后顺序无关,如left top和top left效果一致。
(2)如果只指定了一个方位名词,另一个值省略,则第二个值默认居中对齐。
参数是精确单位 ——background-position :20px 50px
(1)如果参数是精确单位,那么第一个肯定是x坐标,第二个一定是y坐标。
(2)如果只指定一个数值,那该数值一定是x坐标,另一个默认垂直居中。
参数是混合单位——background-position :20px center
(1)如果指定的两个参数是混合单位,则第一个值是x坐标,第二个值是y坐标
3、背景图像固定(背景附着)
background-attachment : scroll | fixed 属性设置背景图像是否固定或者随着页面的其余部分滚动。后期制作视差滚动的效果。

4、背景复合写法
类似与font,但是没有顺序,一般习惯约定顺序为:
background: 背景颜色 背景图片地址 背景平铺 背景图像滚动 背景图片位置
background: red url(URL) no-repeat fixed center top;
5、背景色半透明
background: rgba(0,0,0,0.3) 属性中的a代表透明度alpha,取值范围0~1,可以把0.3的0省略,也就是.3

网友评论