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 |