2011-05-23 102 views
0

我有一個DIV ...添加背景圖片的div(動態內容)

<div id="content"> 

</div> 

現在......在外觀設計上,如果你認爲它是一個矩形具有頂部爲標題,也頁腳是不同的,所以我不能只創建一個1px的背景圖像並重復它。

我會做這樣的事情:

<div id="content"> 
<div id="header">This will have a fixed bg image</div> 
<div id="body-content">This will have a repeated bg image and it's the part that can grow.</div> 
<div id="footer-content">THis will content a fixed bg image for the footer</div> 
</div> 

誰能勸上明智處理這種設計的CSS,請最好的方法是什麼?

+1

請勿使用1px背景圖像,請使用> = 4px背景圖像代替更好的瀏覽器性能。 – 2011-05-23 08:58:09

+0

是頁眉和頁腳固定大小(高度)? – Ibu 2011-05-23 09:02:42

+0

是的,固定大小的高度和寬度。唯一會擴大的是中部地區。 – Satch3000 2011-05-23 09:29:07

回答

2
#header 
{ 
    background-image: url('header.png'); 
    background-repeat: no-repeat; 
} 

#body 
{ 
    background-image: url('body.png'); 
    background-repeat: repeat-y; 
} 

#footer 
{ 
    background-image: url('footer.png'); 
    background-repeat: no-repeat; 
} 
+0

此外,您還需要設置'#header'和'footer'' div'的高度和寬度,因爲背景圖片不會用於計算div的大小。如果未明確設置,圖像可能無法正確顯示。 – 2011-05-23 14:12:14

+0

並確保'background-image:url('XXXX.png');'使用相對於.css文件的路徑。在上面,圖像需要在同一個文件夾中。 – 2011-05-23 14:14:03