简体   繁体   English

@ font-face无法正常工作

[英]@font-face Is Not Working Properly

I am using the Open Sans font from Google fonts in my application using this import rule: 我正在使用此导入规则在应用程序中使用Google字体中的Open Sans字体:

http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800"

When testing locally and I have no internet connection, the font no longer works. 在本地测试并且没有互联网连接时,该字体不再起作用。

What I have tried: 我试过的

I have downloaded this font and set it up inside of my CSS file for @font-face, but it shows all characters are different. 我已经下载了该字体并将其设置在我的CSS文件中,用于@ font-face,但是它显示所有字符都不同。

To fix your issue. 解决您的问题。

1.You first have to download the .ttf file from google fonts. 1.您首先必须从Google字体下载.ttf文件。

2.Put that file in your project and then add following to your css. 2.将该文件放入您的项目中,然后将以下内容添加到您的css中。

3.In url, specify the path of your .ttf file. 3.在URL中,指定.ttf文件的路径。

@font-face {
  font-family: 'Open Sans';
  font-style: normal;
  font-weight: 300;
  src: local('Open Sans Light'), local('OpenSans-Light'), url('your link to .ttf file') format('woff2');
}

使用以下代码在CSS文件中导入Google Web字体。

    @import url('http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800%22');

1st put this inside your head tag 1把它放在你的头标签内

  <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800%22' rel='stylesheet' type='text/css' />

All you need to do is add the font name to your CSS styles. 您需要做的就是将字体名称添加到CSS样式中。 For example: 例如:

h1 { font-family: 'Open Sans', Arial, serif; font-weight: 400; }

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

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