首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用typescript和styled-components在React应用中使用自定义字体

使用typescript和styled-components在React应用中使用自定义字体
EN

Stack Overflow用户
提问于 2020-07-24 04:40:54
回答 1查看 1.6K关注 0票数 0

我有一个来自create- React -app的react应用程序,我正在使用typescript和styled-components

我有一台globalStyles

代码语言:javascript
复制
import {createGlobalStyle} from 'styled-components';

export const GlobalStyle = createGlobalStyle`
    @font-face {
        font-family: 'modernline';
        font-style: normal;
        font-weight: 400;
        src: url("./fonts/modernline.ttf") format('ttf')
    }
`

我在App.tsx中使用了它

代码语言:javascript
复制
import React from 'react';
import {GlobalStyle} from './globalstyle'
// 
import styled from 'styled-components';

export const FontContainer = styled.div`
    font-family: 'modernline';
    font-size: 2em;
    color: red;
`

function App() {
  return (
    <div>
      <GlobalStyle />
      <h1>Font Test</h1>
      <FontContainer>
        Custom Font
      </FontContainer> 
    </div>
  );
}

export default App; 

cusotm字体不显示

在使用typescript和styled-components的create-react-app中使用自定义字体需要做什么

EN

回答 1

Stack Overflow用户

发布于 2020-07-29 01:22:32

这些字体是从您的本地服务器获取的。路径是“./fonts/现代line.ttf”。检查您的网络请求,看看是否一切正常。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63062811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档