css - 如何将 google 字体的使用替换为本地托管字体?

标签 css fonts

我购买了使用两种字体“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");

现在的问题是应用程序托管在无法访问互联网的环境中,因此应用程序看起来很丑陋。

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

有人可以指导我如何模仿此代码,以便字体来自托管应用程序路径而不是 google 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;
}

最佳答案

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

然后使用:

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

检查这个post 包含字体

关于css - 如何将 google 字体的使用替换为本地托管字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56575695/

相关文章:

CSS 在 div 中两个堆叠的背景图像,100% 宽度 50% 高度

asp.net - 控件样式被覆盖

css - 如何使用 CSS3 转换字体样式?

c# - 将字体添加到 CSS 页面

javascript - 如何更改Square付款表格的字体

fonts - 如何使用 FreeType 确定字体中没有字形的所有代码点?

jquery - 如何/在 jquery 移动应用程序中安装 Awesome 字体

jquery - 倒计时结束时显示我的分数

html - 如何正确对齐元素?

html - 垂直对齐标签和文本框