我想知道是否有一种方法可以在谷歌网页字体不可用时使用其他字体源?就像我们检查window.jquery以查看谷歌jquery cdn是否宕机并提供替代文件的方式一样。
我想知道是否有一种方法可以在谷歌网页字体不可用时使用其他字体源?就像我们检查window.jquery以查看谷歌jquery cdn是否宕机并提供替代文件的方式一样。
<link href='https://fonts.googleapisx.com/css?family=Cantarell' rel='stylesheet'>
<style>
@font-face {
font-family: 'cantarellregular';
src: url('cantarell-regular-webfont.eot');
src: url('cantarell-regular-webfont.eot?#iefix') format('embedded-opentype'),
url('cantarell-regular-webfont.woff') format('woff'),
url('cantarell-regular-webfont.ttf') format('truetype'),
url('cantarell-regular-webfont.svg#cantarellregular') format('svg');
font-weight: normal;
font-style: normal;
}
body { font-family: Cantarell, cantarellregular; }
</style>
您需要为服务器中的字体系列取一个不同的名称;在示例中,我使用了FontSquirrel @font-face generator生成的名称。
这样,浏览器将首先尝试从Google网站获取字体文件,如果由于某种原因失败,则会从您的服务器获取字体文件。
我想知道为什么您不直接使用自己服务器上的字体,如果您担心Google网站出现故障。(很少见到它出现故障;但是用户设备与Google网站的连接可能会中断,即使与您的站点的连接正常。)
font-family: 'Skranji', cursive, Verdana, Geneva, sans-serif;