我想在我的代码中捆绑三个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;
}
这是我的捆绑代码:
bundles.Add(new StyleBundle("~/bundles/styles/base").Include("~/Content/Styles/style.css", "~/Content/Styles/normalize.css", "~/Content/Styles/webfont.css"));
有人可以帮我解决问题吗?
答案 0 :(得分:5)
当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"));
答案 1 :(得分:2)
基本上,您可以添加一个转换,将您的css文件中的网址转换为有效的网址。
您可以通过将Bundles配置更改为:
来实现此目的bundles.Add(
new StyleBundle("~/Content/Styles/base-bundle.css")
.Include("~/Content/Styles/style.css", new CssRewriteUrlTransform())
.Include("~/Content/Styles/normalize.css", new CssRewriteUrlTransform())
.Include("~/Content/Styles/webfont.css", new CssRewriteUrlTransform())
);
答案 2 :(得分:0)
您可以将其更改为App_Start> BundleConfig.cs,就像这样
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
将其加载到您的布局页面中,如下所示。
@Styles.Render("~/Content/themes/base/css")