【问题标题】:How to add CSS to ASP.NET site with WebOptimization and Bundling如何使用 WebOptimization 和 Bundling 将 CSS 添加到 ASP.NET 站点
【发布时间】:2014-05-31 20:04:53
【问题描述】:

我创建了一个 ASP.NET 表单站点作为沙盒,并使用 NuGet 添加了我刚刚学习的 Bootstrap。我想改变主题,所以我下载了一个主题并将最小化的文件重命名为theme1-bootstrap.min.css。如果我只是替换现有的 boostrap.min.css,一切都会按预期工作。

但是,我在想(可能是错误的)这不是一个好主意,最好在原始 bootstrap.min.css 之后加载我的主题 bootstrap.min.css。这就是我使用的引用对 html 文件中的语句所做的。

但是 ASP.NET 项目与我使用的 html 参考有点不同,我在任何地方都找不到任何语句。我认为它与 Bundle.config 或 site.master 中的行有关 <webopt:bundlereference runat="server" path="~/Content/css" />

如果知道发生了什么以及应用我的主题的最佳做法是什么,我将不胜感激。谢谢。

【问题讨论】:

    标签: css asp.net twitter-bootstrap


    【解决方案1】:

    看看~/AppStart/BundleConfig.cs:

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

    这意味着 Web 优化将按原样搜索文件 bootstrap.csssite.css 或使用 .min 后缀。 因此,如果您需要将 theme1-bootstrap.min.css 添加到捆绑包中 - 您需要像这样扩展它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 2012-05-22
      • 1970-01-01
      • 2015-09-28
      • 2012-04-15
      相关资源
      最近更新 更多