2012-05-08 70 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;