CSS background 屬性
定義和用法
background 簡寫屬性在一個聲明中設置所有的背景屬性。
可以按順序設置如下屬性:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
如果不設置其中的某個值,也不會出問題,比如 background:#ff0000 url('smiley.gif'); 也是允許的。
通常建議使用這個屬性,而不是分別使用單個屬性,因為這個屬性在較老的瀏覽器中能夠得到更好的支持,而且需要鍵入的字母也更少。
默認值: | not specified |
---|---|
繼承性: | no |
版本: | CSS1 |
JavaScript 語法: | object.style.background="white url(paper.gif) repeat-y" |
瀏覽器支持
所有瀏覽器都支持 background 屬性。
任何的版本的 Internet Explorer (包括 IE8)都不支持屬性值 "inherit"。
可能的值
值 | 描述 |
---|---|
background-color | 規定要使用的背景顏色。參閱:background-color 中可能的值。 |
background-image | 規定要使用的背景圖像。參閱:background-image 中可能的值。 |
background-repeat | 規定如何重復背景圖像。參閱:background-repeat 中可能的值。 |
background-attachment | 規定背景圖像是否固定或者隨著頁面的其余部分滾動。參閱:background-attachment 中可能的值。 |
background-position | 規定背景圖像的位置。參閱:background-position 中可能的值。 |
inherit | 規定應該從父元素繼承 background 屬性的設置。 |
TIY 實例
- 所有背景屬性在一個聲明之中
- 本例演示如何使用簡寫屬性來將所有背景屬性設置在一個聲明之中。
|
|
歡迎大家訪問我的個人網站 萌萌的IT人
posted on 2012-08-03 16:19 一堣而安 閱讀(198) 評論(0) 編輯 收藏 所屬分類: js_css