使用字体在 HTML 中使用本地字体

新手上路,请多包涵

我尝试使用本地字体在 html 中应用样式,下面是代码。字体未应用于 harlow 类使用的元素

<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
    font-family: myFirstFont;
    src:local("C:\Users\Website\fonts\Harlow_Solid_Italic.ttf");
}

.harlow{
    font-family: myFirstFont;
}
</style>
</head>
<body>
<div>With CSS3, websites can finally use fonts other than the pre selected "web-safe" fonts.</div>
<p><b class="harlow">Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule with the WOFF format (only support for EOT format).</p>
</body>
</html>

原文由 anavaras lamurep 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
1 个回答

我做了以下更改,我得到了结果

  • 字体系列的引号

  • 使用 URL 而不是本地

  • 将“\”更改为“/”

注意: 使用 local css 函数会在开发者控制台中引发错误,提示资源未加载。请参阅下面的修改后的代码。

 <!DOCTYPE html>
<html>
<head>
<style>
@font-face {
    font-family: "myFirstFont";
    src: url("C:/Users/Desktop/Website/fonts/Harlow_Solid_Italic.ttf");
}

.harlow {
    font-family: "myFirstFont";
}
</style>
</head>
<body>
<div>With CSS3, websites can finally use fonts other than the pre selected "web-safe" fonts.</div>
<p><b class="harlow">Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule with the WOFF format (only support for EOT format).</p>
</body>
</html>

原文由 anavaras lamurep 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题