css背景樣式包含:背景顏色“background-color”、背景圖片“background-image”、背景定位“background-position”、背景重復“background-repeat”、“background”等。
本教程操作環(huán)境:windows7系統(tǒng)、css3版、dell g3電腦。
1、background-color 設置元素的背景顏色。
background-color:顏色/transparent
說明:
transparent是全透明
顏色值(顏色名/rgb/十六進制)
背景區(qū)包括內容、內邊距(padding)和邊框(border)、不包含外邊距(margin)
2、background-image 設置元素的背景圖片。
background-image:url(圖片地址)/none
說明:
url地址可以是相對地址也可以是絕對地址
元素的背景占據了元素的全部尺寸,包括內邊距和邊框,但不包括外邊距
默認地,背景圖像位于元素的左上角,并在水平和垂直方向上重復。
當即設置了背景圖片又設置了背景顏色時,背景圖片會覆蓋背景顏色
3、background-position 設置背景圖片的起始位置,背景定位
background-position :百分比/px/top/right/bottom/left/center
4、background-attachment 背景圖像是否固定或者隨著頁面的其余部分滾動
background-attachment:scroll/fixed
scroll: 默認值,隨著圖片的滾動而滾動
fixed:當頁面的其余部分滾動時,背景圖片不會移動
5、background-repeat 設置背景圖像是否重復及如何重復
background-repeat:repeat/no-repeat/repeat-x/repeat-y //分別是重復、不重復、水平重復、不重復
6、background 簡寫屬性,作用是將背景屬性設置在一個聲明中。
background:[background-color] [background-image] [background-repeat] [background-attachment] [background-position]
說明:各值之間用空格分割,不分先后順序
(學習視頻分享:css視頻教程)