You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tauri应用中Figtree自定义字体仅部分元素生效问题排查

Tauri应用中自定义字体Figtree仅部分元素生效的问题

我在Tauri应用中尝试使用自定义字体Figtree,但只有部分元素能正常显示该字体,其余元素加载失败。

代码展示

HTML代码

<!DOCTYPE html>
<html>
  <head>
    <title>Window title</title>
    <link href="/style.css" rel="stylesheet"/>
  </head>
  <body>
    <div data-tauri-drag-region id="title-bar">
      <p id="title-bar-title">Window title</p>
      <button class="title-bar-button">Minimize</button>
      <button class="title-bar-button">Maximize</button>
      <button class="title-bar-button">Close</button>
    </div>
    <h1>This is a test.</h1>
  </body>
</html>

CSS代码

:root {
  font-size: 20px;
}

*, ::after, ::before {
  appearance: none;
  box-sizing: border-box;
  font-family: "Figtree" !important;
  text-rendering: optimizeLegibility;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
}

#title-bar {
  display: flex;
}

#title-bar-title {
  display: block;
  flex: 1 1;
  text-align: center;
}

.title-bar-button {
  flex: 0 0;
}

@font-face {
  font-display: block;
  font-family: "Figtree";
  src: url("/assets/Figtree[wght].woff2");
}

@font-face {
  font-display: block;
  font-family: "Figtree";
  font-style: italic;
  src: url("/assets/Figtree-Italic[wght].woff2");
}

当前问题表现

  • 目标:让应用内所有元素都使用Figtree字体
  • 实际情况:只有<h1>元素能正常显示该字体(字重700),其他文本元素均显示后备无衬线字体
  • 移除CSS中的!important后,没有任何元素能加载Figtree字体,怀疑和用户代理样式表有关
  • 通过开发者工具确认:样式表和字体文件已正确加载,“字体”标签下所有元素都标注使用Figtree,但视觉上只有h1生效

环境信息

  • Tauri版本:1.5
  • Figtree字体版本:2.0.3(WOFF2格式)
  • 操作系统:Linux Mint 21.2

补充说明

标题栏div带有data-tauri-drag-region属性,使其表现得像原生标题栏,这可能是问题的关键因素。

应用截图

Tauri应用窗口截图

内容的提问来源于stack exchange,提问作者queerthoughts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 16:56:10