定義和(hé)用法
background 簡寫屬性在一(yī)個聲明(míng)中設置所有的背景屬性。
可(kě)以設置如(rú)下(xià)屬性:
background-color
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment
background-image
如(rú)果不設置其中的某個值,也不會出問(wèn)題,比如(rú) background:#ff0000 url('smiley.gif'); 也是允許的。
通(tōng)常建議(yì)使用這(zhè)個屬性,而不是分别使用單個屬性,因為(wèi)這(zhè)個屬性在較老(lǎo)的浏覽器中能(néng)夠得到更好的支持,而且需要(yào)鍵入的字母也更少(shǎo)。
實例
如(rú)何在一(yī)個聲明(míng)中設置所有背景屬性:
body
{
background: #00FF00 url(bgimage.gif) no-repeat fixed top;
}
CSS 語法
background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;
屬性值
值 | 描述 | CSS |
---|---|---|
background-color | 規定要(yào)使用的背景顔色。 | 1 |
background-position | 規定背景圖像的位置。 | 1 |
background-size | 規定背景圖片的尺寸。 | 3 |
background-repeat | 規定如(rú)何重複背景圖像。 | 1 |
background-origin | 規定背景圖片的定位區(qū)域。 | 3 |
background-clip | 規定背景的繪制區(qū)域。 | 3 |
background-attachment | 規定背景圖像是否固定或者随着頁面的其餘部分滾動。 | 1 |
background-image | 規定要(yào)使用的背景圖像。 | 1 |
inherit | 規定應該從(cóng)父元素繼承 background 屬性的設置。 | 1 |