如果我直接引用_layouts页面中的font-awesome.css
。它会起作用
<link href="~/Content/font-awesome-4.0.3/css/font-awesome.css" rel="stylesheet" />
但是我在BundleConfig.cs
中使用了。图标未显示。
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/font-awesome-4.0.3/css/font-awesome.css",
"~/Content/bootstrap.css",
"~/Content/body.css",
"~/Content/site.css",
"~/Content/form.css"
));
我还观察到浏览器控制台对字体目录有错误。
加载资源失败:服务器响应状态为 404(未找到)http://localhost:51130/fonts/fontawesome-webfont.woff?v=4.0.3
可能是什么问题?
最佳答案
尝试在捆绑时使用 CssRewriteUrlTransform
:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/body.css",
"~/Content/site.css",
"~/Content/form.css"
).Include("~/Content/font-awesome-4.0.3/css/font-awesome.css", new CssRewriteUrlTransform());
这会将 css 文件中的 Assets 的任何 url 更改为绝对 url,因此捆绑不会弄乱相对路径。
关于css - font-awesome 在 MVC5 中不工作 bundleconfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700385/