简体   繁体   English

如何从外部CSS文件导入字体

[英]How to import font face from external css file

I'm trying to import font-family from external css file which is present in CDN. 我正在尝试从CDN中存在的外部css文件导入字体系列。

The file has some font-family defined in the file and I want to import it. 该文件在文件中定义了一些font-family ,我想将其导入。 I have given it a try but I'm not able to get it working. 我已经尝试了一下,但是无法正常工作。

Here is what I have tried: 这是我尝试过的:

@font-face {
    font-family: 'halcom-bold';
    src: url('https://yyyy.net/aso.css');
}

Here is the external CSS code: 这是外部CSS代码:

aso.css

@font-face {
font-family:"halcom";
src:url("https://use.typekit.net/af/657e4d/00000000000000003b9aedc6/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("woff2"),url("https://use.typekit.net/af/657e4d/00000000000000003b9aedc6/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("woff"),url("https://use.typekit.net/af/657e4d/00000000000000003b9aedc6/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("opentype");
font-style:normal;font-weight:700;
}

You can't use @font-face in Firefox with a font hosted on a different domain If you want to specify a font for @font-face using an absolute URL, or a font hosted on a different domain, it needs to be served with Access Control Headers, specifically the Access-Control-Allow-Origin header set to '*' or the domains allowed to request the font. 您不能在Firefox中使用@ font-face,而将字体托管在其他域中如果要使用绝对URL为@ font-face指定字体,或在其他域中托管的字体,则需要提供该字体使用访问控制标头,特别是将Access-Control-Allow-Origin标头设置为“ *”或允许请求字体的域。 This also applies to fonts hosted on a different sub-domain. 这也适用于在其他子域上托管的字体。 If you are using Apache you can try to put this in your .htaccess and restart the server 如果您使用的是Apache,则可以尝试将其放入.htaccess中并重新启动服务器

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
<FilesMatch "\.(ttf|otf|eot)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM