谷歌字体不适用于 Github Pages 上部署的 React 应用程序

帕托里库

我正在为我的应用程序使用样式组件,并且我在 createGlobalStyle 中导入了一个 google 字体 url。

import { createGlobalStyle } from "styled-components";

const GlobalStyles = createGlobalStyle`



* {
    @import url(//fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap);
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Space Mono', monospace;
    font-weight: 400;
}

部署应用程序后,未应用该字体。我试图取代@import从网址https://fonts..http://fonts..,然后现在//fonts..这些是我发现的一些解决方案,对某些人有效,但对我无效。这里似乎有什么问题?

这是已部署应用程序的链接: http://patorikkun.github.io/tip-calculator-app

麦克冯

尝试将@import顶部移动到外部* {}

从:

createGlobalStyle`
* {
    @import url("https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap");
    margin: 0;
    ...
}
...
}`;

到:

createGlobalStyle`
@import url("https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap");

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Space Mono', monospace;
    font-weight: 400;
}

...
}`;

MDN 解释

导入的规则必须在所有其他类型的规则之前,@charset 规则除外;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 github 上部署我的 React 应用程序

在Github Pages上部署

无法在Github Pages上部署新的create-react-app

为什么在尝试将React应用程序部署到GitHub Pages时出现错误?

在 Heroku 上部署 React 应用程序

在Azure上部署React应用程序

如何将一个简单的 React 应用程序作为“用户页面”部署到 Github Pages?

在 github 页面上部署时,`window.location.href` 在 React 应用程序上不起作用

Github提交不适用于桌面应用程序

代码已部署,但页面为空白 - 在 nginx 和 github 页面上部署使用 create react app 创建的 react 应用程序

使用gh-pages在github上部署create-react-app时出现问题

将 React 应用程序部署到 github 页面

在 GitHub 页面上重新部署 React 应用程序

在 Azure Web 应用程序上部署 React - django 应用程序

使用Addon将Ember应用程序部署到Github Pages

部署在github.pages上的Flutter Web应用程序无法访问某些资产

如何在 Github gh-pages 上托管 React 应用程序

在 GitHub Pages 上更新 React 应用程序的最短路径是什么?

在没有 Github 的情况下在 Microsoft Azure 上部署 node js 应用程序

如何在 github 上部署 angular2 cli 应用程序?

在elasticbeanstalk上部署私有github repo golang应用程序

在github上的Azure上部署默认的angular应用程序会出错

GitHub Pages Jekyll主题适用于页面,但不适用于帖子

NativeScript 应用程序名称中的撇号不适用于 Android/ios 部署

响应式设计不适用于heroku部署的Rails应用程序?

为什么 CORS 不适用于我的 express/react 应用程序?

onClick 事件不适用于 React 应用程序,甚至无法使用箭头功能

React Context API不适用于单个应用程序对话框

Selenium-ide,文件上传不适用于React应用程序