custom Font is not loading in ionic framework

15,477

Solution 1

I believe you're going too far back in the directory chain.

I think you want something more like this:

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/opensans-regular-webfont.eot');
    src: url('../fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
    url('../fonts/opensans-regular-webfont.woff') format('woff'),
    url('../fonts/opensans-regular-webfont.ttf') format('truetype'),
    url('../fonts/opensans-regular-webfont.svg') format('svg');
    font-weight: 200;
}
body{
    font-family: 'Open Sans';
}

Here is a tutorial for adding Font Awesome into your project, which is a custom font:

https://www.thepolyglotdeveloper.com/2014/10/use-font-awesome-glyph-icons-ionicframework/

Let me know if that helps you.

Regards,

Solution 2

Your fonts should be located in demoproject/www/lib/ionic/fonts

and then referred to from the css (in it's default location www/css/stylesheet.css like so:

@font-face {
  font-family: 'Open Sans';
  src: url('../lib/ionic/fonts/opensans-regular-webfont.eot');
  src: url('../lib/ionic/fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
  url('../lib/ionic/fonts/opensans-regular-webfont.woff') format('woff'),
  url('../lib/ionic/fonts/opensans-regular-webfont.ttf') format('truetype'),
  url('../lib/ionic/fonts/opensans-regular-webfont.svg') format('svg');
  font-weight: 200;
}
body{
 font-family: 'Open Sans';
}
Share:
15,477

Related videos on Youtube

Muhammad Faizan Khan
Author by

Muhammad Faizan Khan

I am a programmer, TRY to code for Unity3D Projects (not for games officially). Also worked on .Net, C#, HTML\CSS, Javascript, Angular, Jquery, PHP, Bootstrap, Database, SQL, SQL-Server, MySql, Python. If you are in the KHI, let's get for a Tea and Disscuss some good practices about programming. SOreadytohelp Not a good writer at my blog Research And Program

Updated on June 04, 2022

Comments

  • Muhammad Faizan Khan
    Muhammad Faizan Khan almost 2 years

    I want to apply Open Sans font in my Ionic Project. I have use this code inside my SCSS folder where my custom scss file (settings.sccs and other scss files) are located (demoProject\scss_setting.scss)

    @font-face {
      font-family: 'Open Sans';
      src: url('../www/fonts/opensans-regular-webfont.eot');
      src: url('../www/fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
      url('../www/fonts/opensans-regular-webfont.woff') format('woff'),
      url('../www/fonts/opensans-regular-webfont.ttf') format('truetype'),
      url('../www/fonts/opensans-regular-webfont.svg') format('svg');
      font-weight: 200;
    }
    body{
     font-family: 'Open Sans';
    }
    

    fonts are located here(demoProject\www\fonts)

    and try to apply on whole body but console of the browser is showing

     GET http://localhost:8100/www/fonts/opensans-regular-webfont.woff 
    :8100/www/fonts/opensans-regular-webfont.ttf:1
    GET http://localhost:8100/www/fonts/opensans-regular-webfont.ttf 
    
  • bre
    bre almost 9 years
    you are everywhere when i'm looking for some solution about ionic. Great Job!
  • Nic Raboy
    Nic Raboy almost 9 years
    Glad I could help :-)
  • Abhishek Dhote
    Abhishek Dhote over 8 years
    Thanks Nic, was trying for a couple of days finally got it working :)
  • daraul
    daraul over 4 years
    I think @NicRaboy's article has moved to thepolyglotdeveloper.com/2014/10/…