MVC3 中的 CSS 背景图片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6035999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:34:23  来源:igfitidea点击:

CSS background images in MVC3

cssasp.net-mvc-3

提问by Rhonda

I am trying to create style sheet for my MVC3 app. I'm not sure how to format the background-image:url.

我正在尝试为我的 MVC3 应用程序创建样式表。我不确定如何格式化 background-image:url。

background-image:url('../../Content/images/gradient_tile_page_top.png');

or

或者

background-image:url('~/Content/images/gradient_tile_page_top.png');

I've tried both and neither work. Css seems to be a little trickier with MVC.

我两个都试过了,都没用。使用 MVC 的 CSS 似乎有点棘手。

回答by Khepri

If you're following the "norm" your main page layout will have something like:

如果您遵循“规范”,您的主页布局将类似于:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

and your other assets (images for example) will either reside directly in the content folder or in an "images" folder under content.

并且您的其他资产(例如图像)将直接位于内容文件夹中或位于内容下的“图像”文件夹中。

Therefore, in your example:

因此,在您的示例中:

background-image:url('../../Content/images/gradient_tile_page_top.png');

becomes

变成

background-image:url('images/gradient_tile_page_top.png');