简体   繁体   English

使用存储在外部CSS中的字体

[英]use font stored in external css

How do you reference font from a css file? 如何从CSS文件中引用字体? For example, I have css file with the following structure: 例如,我具有以下结构的css文件:

fonts.css file
    @font-face {
      font-family: 'Open Sans';
      font-style: normal;
      font-weight: 400;
      src: local('Open Sans'), local('OpenSans'), url(http://fonts.gstatic.com/s/opensans/v13/u-WUoqrET9fUeobQW7jkRaCWcynf_cDxXwCLxiixG1c.ttf) format('truetype');
    }
    @font-face {
      font-family: 'Open Sans';
      font-style: normal;
      font-weight: 700;
      src: local('Open Sans Bold'), local('OpenSans-Bold'), url(http://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzNqQynqKV_9Plp7mupa0S4g.ttf) format('truetype');
    }

How do I use this font in other css files? 如何在其他CSS文件中使用此字体?

Here is an example : 这是一个例子:

 @font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 400; src: local('Open Sans'), local('OpenSans'), url(http://fonts.gstatic.com/s/opensans/v13/u-WUoqrET9fUeobQW7jkRaCWcynf_cDxXwCLxiixG1c.ttf) format('truetype'); } @font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 700; src: local('Open Sans Bold'), local('OpenSans-Bold'), url(http://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzNqQynqKV_9Plp7mupa0S4g.ttf) format('truetype'); } .mystyle { font-family: "Open Sans"; font-weight: 700; font-size: 24px; } 
 <p class="mystyle">The quick brown fox jumps over the lazy dog</p> 

If your want to use it in another CSS file, on your html page you load first the css containing the font faces declaration, then you load the second css using the first one: 如果要在另一个CSS文件中使用它,请在html页面上首先加载包含字体面孔声明的css,然后使用第一个加载第二个css:

<link rel="stylesheet" href="my_font.css">
<link rel="stylesheet" href="my_other_stylesheet_using_it.css">

That way, in the second css you can use the font faces declared in the first css. 这样,在第二个CSS中,您可以使用第一个CSS中声明的字体。

You can also import the css containing the font faces declaration into another: 您还可以将包含字体面孔声明的css导入另一个:

@import url("base.css");

Look at this: include one CSS file in another 看一下: 在另一个CSS文件中包含一个CSS文件

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

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