css - 如何防止@font-face使用本地文件而不是服务器文件?

标签 css fonts font-face webfonts

访问一个网站时,我发现菜单链接比在同事计算机上使用相同浏览器观看同一页面时异常大胆。 从我的 Windows 字体文件夹中删除相应的字体可以纠正差异。

我的问题是在网站上设计 css 字体时如何防止这种可能性

最佳答案

大多数 @font-face at 规则以 local(name-of-local-file) 开头,然后引用您的远程 url(/on/server/teh-webfont.woff)

在这种典型情况下,浏览器将尝试使用本地文件,如果找不到任何内容,则会继续从您的服务器下载远程资源。如果他们找到本地匹配字体,那么他们将立即使用它并停止搜索字体,因此他们不会下载和使用您的远程资源。

结论:不要使用local(),只保留那些url()。这是contrary of this SO answer

没有 local() 和许多对应多种格式的 url() 的示例。浏览器将下载第一个令他们满意的浏览器,而不是 2 个以上:

@font-face {
    font-family: 'Gudea';
    src: url('./fonts/gudea/Gudea-Regular-webfont.eot');
    src: url('./fonts/gudea/Gudea-Regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('./fonts/gudea/Gudea-Regular-webfont.woff2') format('woff2'),
         url('./fonts/gudea/Gudea-Regular-webfont.woff') format('woff'),
         url('./fonts/gudea/Gudea-Regular-webfont.ttf') format('truetype'),
         url('./fonts/gudea/Gudea-Regular-webfont.svg#gudearegular') format('svg');
    font-weight: normal;
    font-style: normal;
}

关于css - 如何防止@font-face使用本地文件而不是服务器文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36033198/

相关文章:

css 在我的 web2py 应用程序中不起作用

unity-game-engine - <Unity> 我想在下拉菜单(TMP)的模板项标签处添加字体素材

css - 什么是谷歌字体的 "Display"类别/"Display font"

android - @font-face 问题与 phonegap 在 android 上

javascript - 如何在不更改其 css 布局的情况下将 html/css 表单转换为 pdf?

javascript - 使用相同文件的 Html/JS/PHP 两个页面看起来不同(仅在 chrome 中)

css - 垂直分组水平表单元素

javascript - 如何使用 javascript 更改网页上的字体颜色?

ubuntu - 与 Ubuntu Intellij Idea 一起使用的最佳字体

css - Bulletproof 和 FontSquirrel 字体方法在 IE10 中不起作用