來源:http://www.blogjava.net/raozhh/articles/43477.html
背景顏色屬性(background-color)
這個屬性為HTML元素設定背景顏色,相當於HTML中bgcolor屬性。
body {background-color:#99FF00;}
上面的代碼表示Body這個HTML元素的背景顏色是翠綠色的。
演示示例
背景圖片屬性(background-image)
這個屬性為HTML元素設定背景圖片,相當於HTML中background屬性。
<body style="background-image:url(../images/css_tutorials/background.jpg)">
上面的代碼為Body這個HTML元素設定了一個背景圖片。
演示示例
背景重復屬性(background-repeat)
這個屬性和background-image屬性連在一起使用,決定背景圖片是否重復。如果只設置background-image屬性,沒設置background-repeat屬性,在缺省狀態下,圖片既橫向重復,又豎向重復。
repeat-x 背景圖片橫向重復
repeat-y 背景圖片豎向重復
no-repeat 背景圖片不重復
body {background-image:url(../images/css_tutorials/background.jpg); background-repeat:repeat-y}
上面的代碼表示圖片豎向重復。
演示示例
背景附着屬性(background-attachment)
這個屬性和background-image屬性連在一起使用,決定圖片是跟隨內容滾動,還是固定不動。這個屬性有兩個值,一個是scroll,一個是fixed。缺省值是scroll。
body {background-image:url(../images/css_tutorials/background.jpg); background-repeat:no-repeat; background-attachment:fixed}
上面的代碼表示圖片固定不動,不隨內容滾動而動。
演示示例
背景位置屬性(background-position)
這個屬性和background-image屬性連在一起使用,決定了背景圖片的最初位置。
body {background-image:url(../images/css_tutorials/background.jpg);background-repeat:no-repeat; background-position:20px 60px}
上面的代碼表示背景圖片的初始位置距離網頁最左面20px,距離網頁最上面60px。
演示示例
背景屬性(background)
這個屬性是設置背景相關屬性的一種快捷的綜合寫法, 包括background-color, background-image, background-repeat, backgroundattachment, background-position。
body {background:#99FF00 url(../images/css_tutorials/background.jpg) no-repeat fixed 40px 100px}
上面的代碼表示,網頁的背景顏色是翠綠色,背景圖片是background.jpg圖片,背景圖片不重復顯示,背景圖片不隨內容滾動而動,背景圖片距離網頁最左面40px,距離網頁最上面100px。
