【问题标题】:Custom Fonts in JS UWPJS UWP 中的自定义字体
【发布时间】:2017-05-19 13:03:15
【问题描述】:

如何将自定义字体添加到使用 javascript 的通用 Windows 应用程序中?

我把我的字体放在一个新文件夹/fonts/, 我使用 CSS @font-face 添加字体

@font-face {
    font-family: "Montserrat";
    src: url("../font/Montserrat-Regular.ttf");
}

但是当我编译应用程序时, 它给出了错误:

The app couldn’t resolve ms-appx://817ec616-2c4f-44b6-aa98-2108aca6a18a/lib/fonts/Montserrat-Regular.ttf because of this error: DATA_NOT_AVAILABLE.

@font-face failed cross-origin request. Resource access is restricted.

这个错误是否是因为 Visual Studio 中的某些问题?

【问题讨论】:

    标签: javascript visual-studio uwp windows-10-universal webfonts


    【解决方案1】:

    这可能是因为您指的是托管在网络上而不是应用程序包中的 CSS 文件。这将解释跨源问题。如果是这种情况,则指定 URI 的绝对路径。或者,更好的是,将 ttf 文件包含在包中。

    当包含在包中时,自定义字体对我来说很好用。

    如果不是,请尝试其他文件,以检查特定文件是否存在问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-01
      • 2017-03-31
      • 2017-07-27
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      相关资源
      最近更新 更多