在CSS中使用背景网址MVC不能显示图像 - 使用捆绑 [英] MVC cannot display image using background-url in css - uses bundling

查看:208
本文介绍了在CSS中使用背景网址MVC不能显示图像 - 使用捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有以下结构的MVC4项目

I have an MVC4 project which has the following structure:

/Content/css/sprites/topbar.css

/Content/css/sprites/topbar.css

/Content/images/topbar.png

/Content/images/topbar.png

在css文件,我尝试使用引用图片:

In the css file I am trying to reference the image by using:

background: url('../../images/topbar.png')

但不显示图像。如果我改变它,使图像位于:

But the image is not displayed. If I change it so that the image is located in:

/Content/css/sprites/topbar.png

/Content/css/sprites/topbar.png

和更改CSS是:

background: url('content/css/sprites/topbar.png')

它的工作原理,但这种休息,我的项目结构。

it works, but this breaks my project structure.

任何想法?

我没有提到别的东西,因为我不认为这是相关的,但它似乎影响这个!

I didn't mention something else as I didn't think it was relevant, however it appears to affect this!

我用 @ System.Web.Optimization.Styles.Render(〜/ MainStyles)捆绑,然后再缩小CSS,但如果我迈出这一步了,然后它就像我期望的那样。我将如何得到这一切与我的项目结构的工作,并使用捆绑?

I use @System.Web.Optimization.Styles.Render("~/MainStyles") to bundle and minify the css, but if I take that step out, then it works as I would expect. How would I get it all to work with my project structure and using the bundling?

推荐答案

我发现了什么问题了。

这的确是MVC使用的捆绑和缩小。当CSS一直在寻找的图像,它一直在寻找我的束指向作为当前文件夹的文件夹中,而不是文件夹中的css文件位于

It was indeed the bundling and minification used in MVC. When the css was looking for images, it was looking in the folder that my bundle was pointing to as the current folder, rather than the folder the css file is located in.

这篇关于在CSS中使用背景网址MVC不能显示图像 - 使用捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆