div { background-color: 颜色值; }
通常状况下元素背景颜色默认是transparent(透明)。css
div { background-image: none或url(图片的url); }
参数值 | 做用 |
---|---|
none | 无背景图(默认值) |
url | 背景图片的url地址 |
注:url
div { background-repeat: repeat或no-repeat或repeat-x或repeat-y; }
参数值 | 做用 |
---|---|
repeat | 背景图片在纵向和横向上平铺(默认值) |
no-repeat | 不平铺 |
repeat-x | 在横向上平铺 |
repeat-y | 在纵向上平铺 |
div { background-position: x y; }
参数表明的意思是:x坐标和y坐标。能够使用方位名词或精确单位。spa
参数值 | 说明 |
---|---|
length(精确单位) | 百分数,或具体数值(记得加px) |
position(方位名词) | top,center,bottom,left,right |
用于设置背景图像是否固定或随着页面的其他部分移动。code
后期能够制做视差滚动的效果。对象
div { background-attachment: scroll或fixed; }
参数 | 做用 |
---|---|
scroll | 背景图像随对象内容滚动 |
fixed | 背景图像固定 |
当使用简写时,没有特定的书写顺序,提倡顺序为:图片
background: 背景颜色 背景图片url地址 背景平铺 背景图像滚动 背景图片位置;开发
background: rgba(0,0,0,0.3);
注:it
属性 | 做用 | 值 |
---|---|---|
background-color | 背景颜色 | 预约义颜色值、十六进制、rgb代码 |
background-image | 背景图片 | url(图片路径) |
background-repeat | 是否平铺 | repeat、no-repeat、repeat-x、repeat-y |
background-position | 背景位置 | length、position,分别是x和y坐标,单位px |
background-attachment | 背景附着 | scroll、fixed |