我正在尝试在 CSS 中使用 @import 和 @font-face 导入 Google Fonts 字体。我以前只使用 @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");
}
Run Code Online (Sandbox Code Playgroud)
我感觉我导入了两次字体......但它甚至不起作用!(页面显示默认浏览器字体)
感谢您阅读并花时间帮助我。