c# - 样式与文件位置 bundle

标签 c# asp.net asp.net-mvc asp.net-mvc-4 bundle

我想在我的代码中 bundle 三个 css 文件。其中之一用于我的网络字体,我使用“url”。但是当我运行应用程序浏览器时找不到文件。

这是我的 CSS 文件:

@font-face {
    font-family: 'neuropol';
    src: url('../Files/Font/neuropol_x_free-webfont.eot');
    src: url('../Files/Font/neuropol_x_free-webfont.eot?#iefix') format('embedded-opentype'),
         url('../Files/Font/neuropol_x_free-webfont.woff') format('woff'),
         url('../Files/Font/neuropol_x_free-webfont.ttf') format('truetype'),
         url('../Files/Font/neuropol_x_free-webfont.svg#neuropol_x_freeregular') format('svg');
    font-weight: normal;
    font-style: normal;

}  

这是我的 bundle 代码:

bundles.Add(new StyleBundle("~/bundles/styles/base").Include("~/Content/Styles/style.css", "~/Content/Styles/normalize.css", "~/Content/Styles/webfont.css"));

谁能帮我解决这个问题?

最佳答案

当 CSS 定义中有 src URL 时,浏览器将检查相对于它下载 CSS 文件的位置的路径。在这种情况下,这意味着它在 ~/bundles/Files/Font/... 而不是 ~/Content/Files/Font/... 中寻找 src 文件>.

尝试使您的包名称与相对位置匹配。

bundles.Add(new StyleBundle("~/Content/Styles/base-bundle.css").Include("~/Content/Styles/style.css", "~/Content/Styles/normalize.css", "~/Content/Styles/webfont.css"));

关于c# - 样式与文件位置 bundle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15071611/

相关文章:

c# - 获取 RotateTransform 的结果大小

javascript - 如何从 Controller 的 "<select></select>" View 中获取 "ActionResult"的值?

javascript - 从 javascript 链接到 .cshtml View

c# - 当我部署(iis7、asp.net mvc4)时,如何让我的 Visual Studio 解决方案中的文件夹出现在我的服务器上?

c# - 如何使用 MVVM 绑定(bind)到不在我的模型中的数据

C# 覆盖和访问修饰符关键字首选顺序

c# - 多表单、单 View 、ViewModel for MVC Core 2.0

javascript - ASP.NET MVC Controller 接受 javascript 对象

c# - 使用通用集合装箱和拆箱

c# - 使用 Moq 验证事件注册