【问题标题】:Bootstrap and font-awesome in MVC4MVC4 中的 Bootstrap 和 font-awesome
【发布时间】:2013-06-25 10:45:14
【问题描述】:

我正在使用 MVC4,并通过 nuget 添加了 Bootstrap 和 Font Awesome。

我可以看到 Bootstrap 是如何通过下面的BootstrapBundleConfig.cs(由 nuget 包添加的)捆绑的:

public static void RegisterBundles()
{
    BundleTable.Bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap*"));
    BundleTable.Bundles.Add(new StyleBundle("~/Content/bootstrap").Include("~/Content/bootstrap.css", "~/Content/bootstrap-responsive.css"));
}

我有以下问题:

  1. 对于 font-awesome,我没有看到与上面类似的用于注册所需 css 文件的捆绑代码,是否有,或者我只是链接到内容目录中的样式表<link href="~/Content/font-awesome.min.css" rel="stylesheet" /> - 什么是正确的方式?
  2. 对于引导程序,如果我不想要响应式布局,我是否只需将 Include("~/Content/bootstrap.css", "~/Content/bootstrap-responsive.css")) 中的 bootstrap-responsive.css 注释掉?

【问题讨论】:

    标签: asp.net-mvc-4 twitter-bootstrap font-awesome


    【解决方案1】:

    您可以在asp.net 网站上阅读有关捆绑如何工作的更多信息。

    BootStrap nuget 包似乎为您制作了一些捆绑包。您可以修改它以在现有捆绑包中包含 Font Awesome,或使其成为自己的捆绑包

    例如

    public static void RegisterBundles()
    {
        BundleTable.Bundles
            .Add(new ScriptBundle("~/bundles/bootstrap")
            .Include("~/Scripts/bootstrap*"));
    
        // Either add it to the  existing bundle
        BundleTable.Bundles
            .Add(new StyleBundle("~/Content/bootstrap")
            .Include("~/Content/bootstrap.css", 
                    "~/Content/bootstrap-responsive.css",
                    "~/Content/font-awesome.css"));
    
        // Or make it it's own bundle
        BundleTable.Bundles
            .Add(new StyleBundle("~/Content/font-awesome")
            .Include("~/Content/font-awesome.css"));
    
    }
    

    然后,您需要确保您的 _layout.cshtml 呈现这些包(Bootstrap nuget 可能没有为您完成此操作)。

    例如

    @Styles.Render("~/Content/bootstrap")
    
    // Or, if you made it it's own bundle
    @Styles.Render("~/Content/font-awesome")
    

    如果您不想在包中包含 ~/Content/bootstrap-responsive.css,只需从 Include 方法中删除此字符串即可。

    【讨论】:

      猜你喜欢
      • 2013-08-31
      • 1970-01-01
      • 2016-05-02
      • 2013-09-29
      • 2013-06-23
      • 2013-09-07
      • 2018-10-11
      • 2013-05-07
      • 2014-06-02
      相关资源
      最近更新 更多