css - 如何在 React/TypeScript 中正确使用谷歌字体作为材料 ui 自定义主题排版?
问题描述
您好我正在尝试在自定义 Material UI 主题中使用 Google 字体作为全局字体,但字体粗细不起作用。它只显示正常的字体粗细大小,即 400。当我导入另一个字体文件(如 Roboto-bold.woff2)的粗体时,为粗体字体正确编写代码,然后它就像粗体一样工作,只有中等字体粗细不会在这里工作。这是我的代码。
import { createMuiTheme } from '@material-ui/core';
import RobotoReg from '../font/Roboto-Regular.woff2';
import RobotoMed from '../font/Roboto-Medium.woff2';
const robotoReg: any = {
fontFamily: 'Roboto',
fontStyle: 'normal',
fontDisplay: 'swap',
fontWeight: 400,
src: `
local('Roboto-Regular'),
url(${RobotoReg}) format('woff2')
`,
};
const robotoMed: any = {
fontFamily: 'Roboto',
fontStyle: 'normal',
fontDisplay: 'swap',
fontWeight: 400,
src: `
local('Roboto-Medium'),
url(${RoboroMed}) format('woff2')
`,
};
const theme = createMuiTheme({
typography: {
fontFamily: ['Roboto', 'sans-serif',].join(','),
htmlFontSize: 16,
fontSize: 16,
fontWeightRegular: 400,
fontWeightMedium: 500,
},
overrides: {
MuiCssBaseline: {
'@global': {
'@font-face': [robotoReg, robotoMed],
},
},
},
});
...
google 字体作为全局字体效果很好,但 font-weight: 500; 不起作用。有没有人有同样的问题?如果我能得到你的帮助,我将不胜感激!提前致谢。
解决方案
现在可能为时已晚,但值得一提的是:您的代码中有错字:RoboroMed
应该是RobotoMed
.
推荐阅读
- javascript - 使用 JavaScript 的 Microsoft Dynamics 实体表单验证
- h2 - 从 192 升级到 200 时 h2 数据库的升级问题:比例不得大于精度
- ts-jest - ts-jest 只打印出使用信息
- umbraco - 媒体选择器文件名搜索不准确
- java - Hibernate OneToMany 映射和查询生成:找到了多个具有给定标识符的行
- python - 使用 pandas.merge_asof 进行完全外连接
- powershell - PowerShell cmdlet 不适用于字符串连接
- javascript - Javascript 未在 Django 中加载,但 css 和 img 可以
- javascript - 将消息发送到 iframe
- assembly - 在汇编中如何获得字母表中的下一个对应字母以及与前面字符大写相反的字母?