2012-05-08 60 views
0

我有MVC 3應用程序。
在div的一個設置背景圖像。內容未加載?

#wrapper { 
width: 960px; 
margin: 0px auto; 
background: url(../../Content/images/img01.jpg) no-repeat center top; 
} 

在_Layout.cshtml我寫這篇文章:

<div class="wrapper"> 
    <!-- Some Items --> 
</div> 

但圖像不顯示。如果我這樣寫:

<img src="../../Content/images/img01.jpg"/> 

Html-page顯示此圖像正確。

爲什麼這個圖像沒有設置div的背景?

+1

是您在頁面上還是在不同位置的單獨樣式表中張貼的CSS? –

+0

@NathanTaylor在不同的位置 – LuckSound

回答

2

包裝是一類。

您已經定義的CSS爲#這是一個ID

編輯:

只要是很有意義您的代碼必須:

#wrapper { 
    width: 960px; 
    margin: 0px auto; 
    background: url(../../Content/images/img01.jpg) no-repeat center top; 
} 
+0

謝謝)我沒有看到它)) – LuckSound

1

您是否已確認圖像的路徑在CSS文件的上下文中有效?如果CSS文件與您的視圖不在同一個目錄中,則圖像路徑可能無法從CSS文件的位置開始生效。

0

改變這種代碼

background: url(../../Content/images/img01.jpg) no-repeat center top; 

background-image:url('/Content/images/img01.jpg') no-repeat center top;