代码之家  ›  专栏  ›  技术社区  ›  Olivier Boissé

使用MUI时,我真的需要加载Roboto字体吗?

  •  0
  • Olivier Boissé  · 技术社区  · 2 年前

    我可以从Material UI文档中看到,用户负责加载Roboto字体:

    Material UI is designed to use the Roboto font by default. You may add it to your project with npm or yarn via Fontsource, or with the Google Fonts CDN.

    The Roboto font will not be automatically loaded by MUI. You are responsible for loading any fonts used in your application.

    我尝试了他们的一个示例项目( vitejs 一)。我看不到任何装载 Roboto 字体。

    使用启动时 npm run dev ,我可以用 机器人 尽管我在索引html页面中看不到任何这种字体的痕迹。

    我没有看到 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/> 在标题中。我也试着找到 @font-face 在内联样式中没有任何成功。

    我想知道在哪里 机器人 字体来自?它是否默认包含在现代计算机中(我目前在ubuntu笔记本电脑上使用firefox)?

    0 回复  |  直到 2 年前
        1
  •  1
  •   Steve Gomez    2 年前

    TL;博士

    不——你知道 需要 安装Roboto字体以使用MUI,因为它配置有回退(并且您可以覆盖Roboto的使用 globally ),但如果你想遵守 the used version of Google's Material Design guidelines 或者有一个更一致的跨平台UI,你可能想要。

    您最可能看到的是后备字体 (如果本地未安装Roboto,则为系统版本的Helvetica或其他无衬线字体) 。它们看起来确实有些相似,但仔细观察细微之处,你会发现字体不同。(圆角、间距等)

    代码沙盒- MUI with Roboto loaded
    enter image with Roboto loaded

    代码沙盒- MUI without Roboto loaded
    enter image without Roboto loaded

    预装操作系统

    据我所知, Android 是唯一一款预装了Roboto字体的操作系统。

    默认情况下未安装:

    (我找不到Ubuntu预装字体的列表)

    在Firefox上确认

    在Firefox上,可以通过检查一个元素,然后查看“字体”面板的“使用的字体”部分来查看渲染(使用的)字体。

    在Chrome上确认

    在Chrome上,可以通过检查元素,然后查看“计算”选项卡的“渲染字体”部分来查看渲染(使用)的字体。

    有趣的一点——Firefox过去有很多 font loading/rendering problems 这就是为什么我 使用Firefox for dev时存在信任问题。