How to import a new font into a project - Angular 5

前端 未结 3 633
陌清茗
陌清茗 2020-12-02 19:51

I want to import a new font to my Angular 5 project.

I have tried:

1) Copying the file to assets/fonts/

2) adding it to .angular-cli.json

3条回答
  •  有刺的猬
    2020-12-02 20:07

    You can try creating a css for your font with font-face (like explained here)

    Step #1

    Create a css file with font face and place it somewhere, like in assets/fonts

    customfont.css

    @font-face {
        font-family: YourFontFamily;
        src: url("/assets/font/yourFont.otf") format("truetype");
    }
    

    Step #2

    Add the css to your .angular-cli.json in the styles config

    "styles":[
     //...your other styles
     "assets/fonts/customFonts.css"
     ]
    

    Do not forget to restart ng serve after doing this

    Step #3

    Use the font in your code

    component.css

    span {font-family: YourFontFamily; }
    

提交回复
热议问题