背景簡寫
background 屬性可用於設定一個或多個與背景相關的屬性:
| 值 | 描述 | CSS Ver。 | 
|---|---|---|
| background-image | 要使用的背景影象 | 1+ | 
| background-color | 要應用的背景顏色 | 1+ | 
| background-position | 背景圖片的位置 | 1+ | 
| background-size | 背景圖片的大小 | 3+ | 
| background-repeat | 如何重複背景圖片 | 1+ | 
| background-origin | 如何定位背景(當 background-attachment為fixed時忽略) | 3+ | 
| background-clip | 如何相對於 content-box,border-box或padding-box繪製背景 | 3+ | 
| background-attachment | 背景影象的行為方式,無論是與其包含塊一起滾動還是在視口中具有固定位置 | 1+ | 
| initial | 將屬性設定為 value 為 default | 3+ | 
| inherit | 從父級繼承屬性值 | 2+ | 
值的順序無關緊要,每個值都是可選的
句法
背景速記宣告的語法是:
background: [<background-image>] [<background-color>]  [<background-position>]/[<background-size>] [<background-repeat>] [<background-origin>] [<background-clip>] [<background-attachment>] [<initial|inherit>];  
例子
background: red;
只需使用 red 值設定 background-color 即可。
background: border-box red;
將 background-clip 設定為 border-box,將 background-color 設定為紅色。
background: no-repeat center url("somepng.jpg");
將 background-repeat 設定為 no-repeat,將 background-origin 設定為 center,將 background-image 設定為影象。
background: url('pattern.png') green;
在這個例子中,元素的 background-color 將被設定為 green with pattern.png,如果可用的話,覆蓋在顏色上,根據需要重複填充元素。如果 pattern.png 包含任何透明度,那麼 green 顏色將在其後面可見。
background: #000000 url("picture.png") top left / 600px auto no-repeat;
在這個例子中,我們有一個黑色背景,頂部有一個影象’picture.png’,影象不會在任何一個軸上重複,而是位於左上角。位置後的/能夠包括背景影象的大小,在這種情況下,背景影象的大小設定為 600px 寬度,自動高度為 auto。此示例可以與可以淡入純色的特徵影象很好地配合使用。
注意: 即使未給出值,使用速記背景屬性也會重置所有先前設定的背景屬性值。如果你只想修改先前設定的背景屬性值,請改用 longhand 屬性。