CSS添加背景样式
1.背景颜色
background-color:
默认是transparent 即透明的
2.背景图片
background-image: url(路径指定背景图片);
3.背景平铺
background-repeat: no-repeat; 为不平铺
还有以下属性值:repeat,repeat-x,repeat-y.
4.背景图片位置
background-position: x y;
x y可以是方向名词或精确单位
(1)若x,y都是方位名词(left,right,top,bottom,center),则两个词前后顺序无
关.left,top等价于top,left. 若只指定一个参数,则另一个参数默认为center.
(2)若参数都是精确单位,则第一个参数是x,第二个参数是y.若只指定一个参数,则其为x,y默认为居中.
5.背景图像固定
background-attachment
默认值为scroll 背景图像会随页面滚动的
fixed为背景图像固定
6.背景的复合属性
可以将背景属性都写在background里,无固定顺序,一般顺序为:
background: 背景颜色 背景图片地址 背景平铺 背景图像滚动 背景图片位置
7.背景半透明
background: rgba(0,0,0,0.3) a为透明度 1为不透明 0为全透明
只对背景有影响,对其内容无影响