2010-08-30 16 views
4

我一直在使用誰擁有該物業的CSS樣式文件的網頁:有關css風格的兩種背景可能嗎?

body { 
    background: #7a9c12 url(images/main_background.jpg) top center no-repeat; 
    color: #bbb; 
    font: 12px/14px helvetica, arial,Sans-serif; 
} 

正如你可以看到這個代碼只穿對格體頂部中心的背景圖像。但是,我需要在身體標記的底部中心也有一個背景圖像,我該怎麼做?謝謝!

回答

2

,如果你不使用CSS3是對你的htmlbody標籤層中的背景圖片的選項:

html { 
    background: #7a9c12 url(images/main_background_top.jpg) top center no-repeat; 
} 

body { 
    background: url(images/main_background_bottom.jpg) bottom center no-repeat; 
} 

只要確保你只申請了堅實的背景顏色與背景html財產,否則你會覆蓋圖像,只能看到body背景圖像。

1

使用CSS3,您可以有多個背景,用逗號分隔。請參閱documentation。例如

background: url(banner.png) top center no-repeat, 
      url(footer.png) bottom center no-repeat; 
1

對於CSS2.1,不行,這是不可能的。 對於CSS3,是的,你可以。

一個盒子的背景可以在CSS3中有 多個圖層。 圖層的數量由 'background-image'屬性中的 逗號分隔值的數量決定。

參考:W3C

+0

感謝您的答案,我怎樣才能在其中使用css3? – Sohail 2010-12-07 16:03:25