html - 谷歌字体@import + @font-face?

标签 html css fonts

我正在尝试在我的 CSS 中使用带有@import 和@font-face 的 Google 字体导入字体。我以前只对下载的字体使用@font-face,但由于加载需要时间,我更喜欢使用 Google Fonts 方法。

我不希望 Roboto 的“粗体”版本作为我网站中的“粗体”字体,所以我使用了@font-face。但是,我不确定使用它的方式。像这样使用@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");
}

我感觉我导入了两次字体...但它甚至不起作用! (页面显示默认浏览器字体)

感谢您阅读并花时间帮助我。

最佳答案

你可以在你的样式表中这样使用

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

关于html - 谷歌字体@import + @font-face?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48057801/

相关文章:

Javascript 更改元素属性 onmouseover onmouseout

fonts - 如何为基于 GitHub 页面的站点实现基本的页面查看计数器?

html - 检查电子邮件是否匹配模糊

php - 在 php 中使用 html 和 java 脚本标签

css - 使网格区域跨越两行,但不是两列

css - 在Remote Jupyter Notebook中更改字体

html - 字体在本地有效,但在服务器上无效

具有拉伸(stretch)背景的 CSS 布局

javascript - 如何根据 geoJson 功能为每个集群着色不同?

CSS响应式元素之间的绝对位置