简体   繁体   English

Google字体@import + @ font-face?

[英]Google Font @import + @font-face?

I'm trying to import fonts with Google Fonts with @import and @font-face, in my CSS. 我正在尝试在CSS中使用@import和@ font-face导入带有Google字体的字体。 I used to only use @font-face with downloaded fonts, but since it takes time to load, I preferred to use the Google Fonts method. 我曾经只将@ font-face与下载的字体一起使用,但是由于加载需要花费时间,因此我更喜欢使用Google Fonts方法。

I didn't wanted the "bold" version of Roboto as the "bold" font in my website, so I used @font-face. 我不想将Roboto的“粗体”版本用作网站中的“粗体”字体,因此我使用@ font-face。 However, I'm not sure of the way to use it. 但是,我不确定使用它的方式。 Is this correct to use @import and @font-face like this? 这样使用@import和@ font-face是否正确?

@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i');

@font-face
{
    font-family: Roboto;
    src: url("https://fonts.googleapis.com/css?family=Roboto:400");
}

@font-face
{
    font-family: Roboto;
    font-weight: bold;
    src: url("https://fonts.googleapis.com/css?family=Roboto:500");
}

@font-face
{
    font-family: Roboto;
    font-style: italic;
    src: url("https://fonts.googleapis.com/css?family=Roboto:400i");
}

@font-face
{
    font-family: Roboto;
    font-weight: bold;
    font-style: italic;
    src: url("https://fonts.googleapis.com/css?family=Roboto:500i");
}

I've the feeling I'm importing the fonts twice... but it doesn't even work! 我感觉我要两次导入字体...但是它甚至不起作用! (The page displays the default browser font) (页面显示默认浏览器字体)

Thank you for reading and taking time to help me. 感谢您阅读并抽出宝贵时间来帮助我。

you can use like this in your stylesheet 你可以在样式表中这样使用

@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i');
h2{
font-family:Roboto;
}

@font-face make sense when you loading font from files on your server. 从服务器上的文件加载字体时,@ font-face很有意义。 If you importing from google, use only import and write right properties to elements you want. 如果您是从Google导入,请仅使用import并将正确的属性写入所需的元素。

@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i');

h2 {
   font-family:Roboto;
   font-weight: 500;
}

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

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