1.背景的五種基本屬性:background-color(背景顏色)、background-image(背景圖片)、background-repeat(背景圖片展示方式)、background-attachment(背景圖片是固定還是滾動)、background-position(背景圖片位置)。綜合使用:background:[<background-color>][<background-image>][<background-repeat>][<background-attachment>][<background-position>]
2.background-color屬性
語法:background-color:transparent || <color>
transparent:透明色
color:顏色名、rgb色、hsl值、十六進制值、rgba色、hsla值
3.background-image屬性
語法:background-image:none || <url>
none為默認值,表示沒有
url:圖片地址,可以是相對地址,也可以是絕對地址
4.background-repeat屬性
語法:background-repeat:repeat || repeat-x || repeat-y || no-repeat
repeat:背景圖片沿X軸和Y軸方向平鋪
repeat-x:背景圖片沿X軸方向平鋪
repeat-y:背景圖片沿Y軸方向平鋪
no-repeat:背景圖片不做任何平鋪
5.background-attachment屬性
語法:background-attachment:scroll || fixed
scroll:背景圖片隨著頁面的其余部分滾動
fixed:背景圖片固定不動
注:取值fixed時,運用在html或body標簽上,使用在其他標簽不能達到固定效果
6.background-position屬性
語法:background-position:[percentage] || [length] || [left | center | right] || [top | center | bottom]
作用:用來設置背景圖片的位置
默認值:(0,0) || (0%, 0%) || (left top),其值可以是具體的百分數或數值設置(可以是負值),也可以使用關鍵字left、center、top、right、bottom配合設置。各屬性定位方式: