Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why font-awesome works on localhost but not on web ?

I'm using font awesome in my project(mvc/asp.net). My problem is, I was debugging the project and check on localhost, there was no problem with font awesome icons. But when published the website and check on web, instead of icons, i saw small boxes. I'm sure that it's placed in right directory(where css files placed).

I couldn't find any proper solution.

By the way there is also no problem with buttons. They are all ok but icons are gone.

Thanks

like image 489
ethelrsn Avatar asked Feb 15 '13 12:02

ethelrsn


People also ask

Why is Font Awesome not working in HTML?

Make sure that the Font Awesome CSS file is loaded and that the "webfonts" folder is not missing in the website project. To check whether the CSS file is loaded well, open your page source code on a web browser by right-clicking on the page and selecting "View page source" or by pressing Ctrl+U while on the page.

Can I use Font Awesome on my website?

Font Awesome CDN Easiest Font Awesome CDN is the easiest way to get Font Awesome on your website or app, all with just a single line of code. No downloading or installing!

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.


7 Answers

Why font-awesome works on debug mode but not on IIS?

In Visual Studio, by default, some font files are not including during Publish:

  • .eot
  • .json
  • .ttf
  • .woff

This is because their build action is set to None, this is by default (on MVC, not sure on WebForms). You must go to the affected file's properties and set it from "None" to "Content".

enter image description here

This is how I solved it (not by manually dragging the files as some may suggest)

Credits goes to this guy: http://edsykes.blogspot.com/2012/09/aspnet-build-actions-with-ttf-eot-and.html

like image 35
Yorro Avatar answered Oct 05 '22 19:10

Yorro


I've just loaded your webpage and checked the net tab of firebug.

your following urls returned a 404:

http://www.senocakonline.com/Content/font/fontawesome-webfont.woff

http://www.senocakonline.com/Content/font/fontawesome-webfont.ttf

i would assume that those being missing is the reason your icons aren't displaying.

UPDATE: 23.10.2015 to make it available just add this code to your WebConfig:

<system.webServer>
    <staticContent>
      <mimeMap fileExtension="woff" mimeType="application/font-woff" />
      <mimeMap fileExtension="woff2" mimeType="application/font-woff" />
    </staticContent>
</system.webServer>
like image 177
AdamWhite Avatar answered Oct 05 '22 19:10

AdamWhite


Another solution that solved this issue for me can be found here: https://stackoverflow.com/a/12587256/615285

Quoting from there:

The issue is most likely that the icons/images in the css files are using relative paths, so if your bundle doesn't live in the same app relative path as your unbundled css files, they become broken links.

The easist thing to do is to have your bundle path look like the css directory so the relative urls just work, i.e:

new StyleBundle("~/Static/Css/bootstrap/bundle")

We have added support for this in the 1.1beta1 release, so to automatically rewrite the image urls, you can add a new ItemTransform which does this rebasing automatically.

bundles.Add(new StyleBundle("~/bundles/publiccss").Include(
            "~/Static/Css/bootstrap/bootstrap.css",
            "~/Static/Css/bootstrap/bootstrap-padding-top.css",
            "~/Static/Css/bootstrap/bootstrap-responsive.css",
            "~/Static/Css/bootstrap/docs.css", new CssRewriteUrlTransform()));
like image 34
Mason240 Avatar answered Oct 05 '22 19:10

Mason240


I had the same problem. The solution:

  1. Open CSS file and delete the current font-face section and replace with these:

    @font-face {
    
        font-family: FontAwesome;
        src: url('/Content/fonts/fontawesome-webfont.eot'), /*for IE */
             url('/Content/fonts/fontawesomewebfont.svg'),
             url('/Content/fonts/fontawesome-webfont.ttf'); /* for CSS3 browsers */
        font-weight: normal;
        font-style: normal;
    }
    

    (change the font-face values as you want)

  2. Copy your ttf font file on your desktop then convert to eot

    http://www.kirsle.net/wizards/ttf2eot.cgi

  3. Convert ttf font file to svg

    http://www.freefontconverter.com/

  4. Convert ttf font file to woff (optional)

    http://ttf2woff.com/

  5. Drag and drop these all fonts (ttf, eot, svg, woff... ) to your file location when Visual Studio 2012 is open.

  6. Publish your project

like image 28
Mr. Zoidberg Avatar answered Oct 05 '22 18:10

Mr. Zoidberg


It depends on this code line in BundleConfig:

        BundleTable.EnableOptimizations = true;

if it is true, you have to change your Font files's path;

../ is shows root path, main folder of your project. And then you have to write rest of the path.

Mine. When it's true:

font-family: 'Icons';
    src:url('../_include/css/fonts/Icons.eot');
    src:url('../_include/css/fonts/Icons.eot?#iefix') format('embedded-opentype'),
        url('../_include/css/fonts/Icons.woff') format('woff'),
        url('../_include/css/fonts/Icons.ttf') format('truetype'),
        url('../_include/css/fonts/Icons.svg#Icons') format('svg');
    font-weight: normal;
    font-style: normal;

When it's false:

font-family: 'Icons';
    src:url('fonts/Icons.eot');
    src:url('fonts/Icons.eot?#iefix') format('embedded-opentype'),
        url('fonts/Icons.woff') format('woff'),
        url('fonts/Icons.ttf') format('truetype'),
        url('fonts/Icons.svg#Icons') format('svg');
    font-weight: normal;
    font-style: normal;
like image 45
Ebleme Avatar answered Oct 05 '22 18:10

Ebleme


It is also a MIME TYPE problem in the IIS, just add the file extension .woff and it will work

like image 39
Bachask8 Avatar answered Oct 05 '22 19:10

Bachask8


this worked for me : < link href="~/Content/font-awesome-4.2.0/css/font-awesome.css" rel='stylesheet' type='text/css' />

I had to link the Directly URl

like image 39
Michael Mora Montero Avatar answered Oct 05 '22 18:10

Michael Mora Montero