css - 字体文件不在 angular2 中呈现

标签 css angular fonts angular-cli

我在 assets/font 文件夹中添加字体文件,然后创建名为 fontiran.css

的波纹管 css 文件
@font-face {
    font-family: IRANSans;
    font-style: normal;
    font-weight: bold;
    src: url('.//iran.font/eot/IRANSansWeb(FaNum)_Bold.eot');
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_Bold.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('./iran.font/woff2/IRANSansWeb(FaNum)_Bold.woff2') format('woff2'),  /* FF39+,Chrome36+, Opera24+*/
         url('./iran.font/woff/IRANSansWeb(FaNum)_Bold.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+*/
         url('./iran.font/ttf/IRANSansWeb(FaNum)_Bold.ttf') format('truetype');
}
@font-face {
    font-family: IRANSans;
    font-style: normal;
    font-weight: 500;
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_Medium.eot');
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_Medium.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('./iran.font/woff2/IRANSansWeb(FaNum)_Medium.woff2') format('woff2'),  /* FF39+,Chrome36+, Opera24+*/
         url('./iran.font/woff/IRANSansWeb(FaNum)_Medium.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+*/
         url('./iran.font/ttf/IRANSansWeb(FaNum)_Medium.ttf') format('truetype');
}
@font-face {
    font-family: IRANSans;
    font-style: normal;
    font-weight: 300;
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_Light.eot');
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_Light.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('./iran.font/woff2/IRANSansWeb(FaNum)_Light.woff2') format('woff2'),  /* FF39+,Chrome36+, Opera24+*/
         url('./iran.font/woff/IRANSansWeb(FaNum)_Light.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+*/
         url('./iran.font/ttf/IRANSansWeb(FaNum)_Light.ttf') format('truetype');
}
@font-face {
    font-family: IRANSans;
    font-style: normal;
    font-weight: 200;
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_UltraLight.eot');
    src: url('./iran.font/eot/IRANSansWeb(FaNum)_UltraLight.eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('./iran.font/woff2/IRANSansWeb(FaNum)_UltraLight.woff2') format('woff2'),  /* FF39+,Chrome36+, Opera24+*/
         url('./iran.font/woff/IRANSansWeb(FaNum)_UltraLight.woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+*/
         url('./iran.font/ttf/IRANSansWeb(FaNum)_UltraLight.ttf') format('truetype');
}
@font-face {
    font-family: IRANSans;
    font-style: normal;
    font-weight: normal;
    src: url('./iran.font/eot/IRANSansWeb(FaNum).eot');
    src: url('./iran.font/eot/IRANSansWeb(FaNum).eot?#iefix') format('embedded-opentype'),  /* IE6-8 */
         url('./iran.font/woff2/IRANSansWeb(FaNum).woff2') format('woff2'),  /* FF39+,Chrome36+, Opera24+*/
         url('./iran.font/woff/IRANSansWeb(FaNum).woff') format('woff'),  /* FF3.6+, IE9, Chrome6+, Saf5.1+*/
         url('./iran.font/ttf/IRANSansWeb(FaNum).ttf') format('truetype');
}

然后将样式表文件添加到angular-cli.json:

"styles": [  
     ...
        "./assets/font/fontiran.css",
     ...
         "styles.css"    

      ],

然后将字体系列名称添加到正文中:

body{
font-family:font-family: IRANSans;
}

在运行时,我检查了元素,我看到 fontirans.css 已呈现,但在网络选项卡中我没有看到 ttf、eot 和 woff 文件。

最佳答案

一个选项是使用 base64 编码。 前往网站 https://transfonter.org/并上传字体,勾选Base64编码。 祝你好运

关于css - 字体文件不在 angular2 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48033054/

相关文章:

html - 如何在任何显示器上的相同位置显示一个 div 而不管物理尺寸

css - EM单元如何有助于响应式设计

javascript - HTML Select2 与内联按钮对齐

HTML/CSS - 使用浏览器更改按钮大小

javascript - ngrx/effect 将数据传递给运算符(operator)

angular - 在加载第一个组件之前在 Angular 中显示预加载器

java - 在 Java 应用程序中使用自定义字体时出现打印问题

css - Flex - 如何使用 CSS 在 spark RichText 中嵌入多种字体?

Angular6 表单验证

javascript - programmers.stackexchange.com 如何在其导航菜单中实现自定义字体?