font-face - AMP:使用字体的自定义字体不起作用
问题描述
我正在尝试在我的 AMP 页面中使用使用 font-face 的自定义字体,但该字体未呈现。控制台显示“图标的字体下载超时”。
@font-face {
font-family: 'icons';
src: url('/fonts/icos2/icomoon.ttf?126oo9') format('truetype');
font-weight: normal;
font-style: normal;
}
[class^="icon-"], [class*=" icon-"] {
font-family: 'icons';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-clock:before {
content: "\e94e";
}
<script async custom-element="amp-font" src="https://cdn.ampproject.org/v0/amp-font-0.1.js"></script>
<amp-font layout="nodisplay"
font-family="icons"
timeout="2000"
on-error-remove-class="icons-loading"
on-error-add-class="icons-missing"
on-load-remove-class="icons-loading"
on-load-add-class="icons-loaded">
</amp-font>
<span class="icon-clock"></span>
<span class="ribbon-txt">Text</span>
字体是通过 HTTPS 获取的。
任何帮助将不胜感激。
谢谢!
解决方案
头上的 Js
<script async custom-element="amp-font" src="https://cdn.ampproject.org/v0/amp-font-0.1.js"></script>
头上的 CSS
<style amp-custom>
h1 {
color: red;
}
@font-face {
font-family: 'icomoont';
src: url(https://www.fanaticguitars.com/download/icomoon.ttf) format('truetype');
}
.font {font-family: 'icomoont'; color:#f00;}
span {font-size:25px;}
[class^="icon-"], [class*=" icon-"] {
font-family: 'icomoont';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-clock:before {
content: "\e94e";
}
</style>
HTML
<span>Hello Font!</span>
<br>
<span class="font">Hello Font!</span>
<br>
<span class="icon-clock"></span>
<span class="ribbon-txt">Text</span>
推荐阅读
- javascript - 在正则表达式匹配中打断句子并使用 javascript 创建数组
- markdown - Sphinx - 如何维护页面之间的侧边栏内容?
- reactjs - 带有 React 的事件 onClick - 未调用函数
- java - 大十进制。multiply() 和 divide() 方法返回十六进制数。为什么?
- c# - WebSocketSharp 的最大短信大小是多少?
- special-characters - 如何在 Jabref 中添加连字符或西班牙语单词以在 Lyx 中引用?
- python - 根据另一列的值增加列值
- javascript - 从远程文件夹导入图像的语法是什么?
- linear-programming - GLPK - 上限约束不能正常工作
- python - 允许用户在提交之前编辑或删除 Flask 上上传文件的列表