css背景樣式
序號 中文說明 標記語法
1 背景顏色 {background-color:數值}
2 背景圖片 {background-image: url(http://www.survivalescaperooms.com/URL)|none}
3 背景重復 {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}
4 背景固定 {background-attachment:fixed|scroll}
5 背景定位 {background-position:數值|top|bottom|left|right|center}
6 背影樣式 {background:背景顏色|背景圖象|背景重復|背景附件|背景位置}
1.背景顏色:background-color
語法: {background-color:數值}
說明: 參數取值和顏色屬性一樣
注意: 在 HTML當中,要為某個對象加上背景色只有一種辦法,那就是先做一個表格,在表格中設置完背景色,再把對象放進單元格。這樣做比較麻煩,不但代碼較多,還要為表格的大小和定位傷些腦筋。現在用CSS就可以輕松地直接搞定了,而且對象的范圍很廣,可以是一段文字,也可以只是一個單詞或一個字母。
例子: <span style="background-color:red">給部分文字加背景顏色</span>給部分文字加背景顏色
表格背影顏色:style="background-color:red"
2.背景圖片:background-image
語法: {background-image: url(http://www.survivalescaperooms.com/URL)|none}
說明: URL就是背景圖片的存放路徑。如果用“none”來代替背景圖片的存放路徑,將什么也不顯示。
例子: 給部分文字加背景圖片 .imgbgstyle { background-image: url(http://www.survivalescaperooms.com/logo.gif)}
3.背景重復:background-repeat
語法: {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}
作用: 背景圖片重復控制的是背景圖片平鋪與否,也就是說,結合背景定位的控制可以在網頁上的某處單獨顯示一幅背景圖片
說明: 參數取值范圍:
·inherit 繼承
·no-repeat 不重復平鋪背景圖片
·repeat
·repeat-x 使圖片只在水平方向上平鋪
·repeat-y 使圖片只在垂直方向上平鋪
注意: 如果不指定背景圖片重復屬性,瀏覽器默認的是背景圖片向水平、垂直兩個方向上平鋪。
4.背景固定:background-attachment
語法: {background-attachment:fixed|scroll}
說明: 參數取值范圍
·fixed:網頁滾動時,背景圖片相對于瀏覽器的窗口而言,固定不動
·scroll:網頁滾動時,背景圖片相對于瀏覽器的窗口而言,一起滾動
注意: 背景圖片固定控制背景圖片是否隨網頁的滾動而滾動。如果不設置背景圖片固定屬性,瀏覽器默認背景圖片隨網頁的滾動而滾動。為了避免過于花哨的背景圖片在滾動時傷害瀏覽者的視力,所以可以解除背景圖片和文字內容的捆綁,該為和瀏覽器窗口捆綁。
例子: 使背景圖案不隨文字“滾動”的CSS
BODY { background: purple url(http://www.survivalescaperooms.com/bg.jpg); background-repeat:repeat-y; background-attachment:fixed }
5.背景定位:background-position
語法: {background-position:數值|top|bottom|left|right|center}
作用: 背景定位用于控制背景圖片在網頁中顯示的位置。
說明: 參數取值范圍
·帶長度單位的數字參數
·top:相對前景對象頂對齊
·bottom:相對前景對象底對齊
·left:相對前景對象左對齊
·right:相對前景對象右對齊
·center:相對前景對象中心對齊
·比例關系
關鍵字解釋如下:
top left = left top = 0% 0%
top = top center = center top = 50% 0%
right top = top right = 100% 0%
left = left center = center left = 0% 50%
center = center center = 50% 50%
right = right center = center right = 100% 50%
bottom left = left bottom = 0% 100%
bottom = bottom center = center bottom = 50% 100%
bottom right = right bottom = 100% 100%
注意: 參數中的center如果用于另外一個參數的前面,表示水平居中;如果用于另外一個參數的后面,表示垂直居中。
新聞熱點
疑難解答