校內網css代碼添加背景圖片常用代碼

來源:互聯網
上載者:User

序號 中文說明 標記文法 備忘
1 背景顏色 {background-color:數值}
2 背景圖片 {background-image: url(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就可以輕鬆地直接搞定了,而且對象的範圍很廣,可以是一段文字,也可以只是一個單詞或一個字母。
例子:給部分文字加背景顏色給部分文字加背景顏色
表格背影顏色:style="background-color:red"

2.背景圖片:background-image

文法:{background-image: url(URL)|none}
說明: URL就是背景圖片的存放路徑。如果用“none”來代替背景圖片的存放路徑,將什麼也不顯示。
例子:給部分文字加背景圖片 .imgbgstyle { background-image: url(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(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如果用於另外一個參數的前面,表示水平置中;如果用於另外一個參數的後面,表示垂直置中。
6. 背景樣式:background

文法:{background:背景顏色|背景圖象|背景重複|背景附件|背景位置}
作用:背景屬性是一個更明確的背景—關係屬性的略寫。以下是一些背景的聲明:
例子:
BODY { background: white url(http://www.htmlhelp.com/foo.gif) }
BLOCKQUOTE { background: #7fffd4 }
P { background: url(../backgrounds/pawn.png) #f0f8ff fixed }
TABLE { background: #0c0 url(leaves.jpg) no-repeat bottom right }
注意:當一個值未被指定時,將接受其初始值。例如,在上述的前三條規則,背景位置屬性將被設定為0% 0%。為了避免與使用者的樣式表之間的衝突,背景和顏色應該一起被指定。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.