我想在我的代码中 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/