angular - Angular8:为每条路线加载不同的谷歌字体
问题描述
我正在为我的前端项目使用 Angular8,并且我遇到了需要为每个角度路径使用不同的谷歌字体的情况。
一种可能的解决方案是,我通过在 head 部分中导入项目中需要的所有 google 字体并font-family
在组件 CSS 文件中进行更改来导入它们。但这里的缺点是我需要在第一次加载应用程序时不必要地下载所有谷歌字体。
任何人都可以建议一种方法来为每条路线加载一种谷歌字体吗?
解决方案
您可以@import
在要更改 google 字体的每个 css 或路由中使用。
组件 1 css
@import url('https://fonts.googleapis.com/css?family=Odibee+Sans&display=swap');
p {
font-family: 'Odibee Sans', cursive; /* Use font family anywhere in the component */
}
组件 2 css
@import url('https://fonts.googleapis.com/css?family=Tomorrow&display=swap');
p {
font-family: 'Tomorrow';
}
演示堆栈闪电战。
推荐阅读
- elixir - Elixir Phoenix Plugs 及其放置位置
- mongodb - MongoDB:对 UTF-8 字符串进行排序
- javascript - Javascript - 创建和填充包含子数组的关联数组
- json - JSON VB.Net 的类
- itext - iText PdfSmartCopy 正在创建重复字体
- elasticsearch - 无法索引/发现 Elassandra 中的多个字段
- javascript - JQuery Datatable 标头与 tbody 不对齐?
- statistics - ANOVA 结果不一致(AIC VS 偏差)
- java - Apache nifi 无法启动
- python-3.x - Python + BeautifulSoup:由于网站的格式,似乎无法从网站上抓取我想要的特定数据