即使使用@import捆绑css [英] Bundling css even if using @import

查看:91
本文介绍了即使使用@import捆绑css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#和Asp.Net MVC开发应用程序.我有多个css文件,一个叫做 base.css ,然后使用 @import 规则将其导入其他css文件:

I'm developing an application in C# and Asp.Net MVC. I have various css files one called base.css which I then import into other css files using @import rule as:

@import url('base.css');

然后我将css文件打包以将其最小化为:

Then I bundle my css files to minimise them as:

bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));
                  ... more css files

所以我的问题是,即使将 base.css 导入到另一个CSS中,我也必须捆绑它吗?因为如果我不笨拙,那么样式将无法按要求工作.

So my question is do I have to bundle base.css even if I'm importing it into a different css? Because if I don't bunble it then the styling doesn't work as required.

推荐答案

由于MVC Bundler在可能不同的位置(请参见捆绑包名称中的完整路径)(这些 import的位置)创建了一个全新文件语句现在变得不准确.

Because the MVC Bundler creates an entirely new file in a potentially different location (see the full path in your bundle name), the location of those import statements now becomes inaccurate.

您可以做的是创建一个单独的CSS文件(或 _Layout 页面上的静态声明,仅包含那些 import 语句),并将其包含在外部任何捆绑包.

What you can do instead is to create a separate CSS file (or static declaration on your _Layout page that includes only those import statements), and include that outside of any bundle.

这篇关于即使使用@import捆绑css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆