Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

font-awesome not working bundleconfig in MVC5

If I direct refer to font-awesome.css in _layouts page. it will work

<link href="~/Content/font-awesome-4.0.3/css/font-awesome.css" rel="stylesheet" /> 

But I used in BundleConfig.cs. Icon is not showing.

 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"                      )); 

and also I observed browser console have error to font directory. Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:51130/fonts/fontawesome-webfont.woff?v=4.0.3

what could be the problem?

like image 523
James123 Avatar asked Mar 27 '14 22:03

James123


People also ask

How do I use Font Awesome 5?

To use the Free Font Awesome 5 icons, you can choose to download the Font Awesome library, or you can sign up for an account at Font Awesome, and get a code (called KIT CODE) to use when you add Font Awesome to your web page.

Can Font Awesome work offline?

To be able to use font awesome offline you would have to manually download the icons to your local computer. You should be able to find the required files from the font awesome website.

How do I increase font size in awesome?

To increase icon sizes relative to their container, use the fa-lg (33% increase), fa-2x , fa-3x , fa-4x , or fa-5x classes. If your icons are getting chopped off on top and bottom, make sure you have sufficient line-height.


1 Answers

Try using CssRewriteUrlTransform when bundling:

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()); 

This changes any urls for assets from within the css file to absolute urls so the bundling doesn't mess up the relative path.

Docs for CssRewriteUrlTransform

like image 99
Simon C Avatar answered Sep 25 '22 22:09

Simon C