【问题标题】:How to replace the use of google fonts to local hosted fonts?如何将使用谷歌字体替换为本地托管字体?
【发布时间】:2019-06-13 16:44:35
【问题描述】:

我购买了使用两种字体“roboto”和“open sens”的主题,并在 site.css 下以下列方式使用

@import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700");
@import url("https://fonts.googleapis.com/css?family=Roboto:400,300,500,700");

现在的问题是应用程序托管在没有互联网访问权限的环境下,因此应用程序看起来很丑陋。

我下载了这两种字体并尝试在本地引用,但似乎我没有正确引用,因为我可以看到样式还不是必须的。

有人可以指导我如何模仿这段代码,以便字体来自托管应用程序路径而不是谷歌 url,而不会改变设计。

参考:我尝试了以下但没有运气。(字体路径正确,我仔细检查了)

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-ExtraBoldItalic.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-ExtraBoldItalic.woff') format('woff');
    font-weight: 800;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Italic.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Italic.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Light.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Light.woff') format('woff');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Regular.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-Italic.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-Italic.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-LightItalic.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-LightItalic.woff') format('woff');
    font-weight: 300;
    font-style: italic;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-SemiBold.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-SemiBold.woff') format('woff');
    font-weight: 600;
    font-style: normal;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-ThinItalic.woff2') format('woff2'), url('../fonts/Roboto/Roboto-ThinItalic.woff') format('woff');
    font-weight: 100;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Thin.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Thin.woff') format('woff');
    font-weight: 100;
    font-style: normal;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Medium.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-Light.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-Light.woff') format('woff');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-SemiBoldItalic.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-SemiBoldItalic.woff') format('woff');
    font-weight: 600;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-BlackItalic.woff2') format('woff2'), url('../fonts/Roboto/Roboto-BlackItalic.woff') format('woff');
    font-weight: 900;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Black.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Black.woff') format('woff');
    font-weight: 900;
    font-style: normal;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-BoldItalic.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-BoldItalic.woff') format('woff');
    font-weight: bold;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-Bold.woff2') format('woff2'), url('../fonts/Roboto/Roboto-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-ExtraBold.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-ExtraBold.woff') format('woff');
    font-weight: 800;
    font-style: normal;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-MediumItalic.woff2') format('woff2'), url('../fonts/Roboto/Roboto-MediumItalic.woff') format('woff');
    font-weight: 500;
    font-style: italic;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-Bold.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-LightItalic.woff2') format('woff2'), url('../fonts/Roboto/Roboto-LightItalic.woff') format('woff');
    font-weight: 300;
    font-style: italic;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto/Roboto-BoldItalic.woff2') format('woff2'), url('../fonts/Roboto/Roboto-BoldItalic.woff') format('woff');
    font-weight: bold;
    font-style: italic;
}

@font-face {
    font-family: 'Open Sans';
    src: url('../fonts/Open_Sans/OpenSans-Regular.woff2') format('woff2'), url('../fonts/Open_Sans/OpenSans-Regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

【问题讨论】:

  • 这似乎是一些路径问题,那么您能否分享一些我们可以提供帮助的代码。

标签: css fonts


【解决方案1】:

下载 Google 字体 并将其放入您的项目中。 (ttf 文件)

然后使用:

@font-face {
  font-family: 'Your-font-Name-for-usage';
  src: url('your-path-font.ttf')  format('truetype')
}

选中此post包含字体

【讨论】:

    猜你喜欢
    • 2021-09-11
    • 2022-08-06
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 2019-05-23
    • 2018-02-17
    • 2015-04-10
    • 1970-01-01
    相关资源
    最近更新 更多