لماذا نضطر إلى استخدام الخطوط المجمعة مع واجهة المستخدم المادية؟
هل هناك طريقة لإزالة أو تكوين هذا؟
في الواقع ، بعد 6 ساعات من البحث على الإنترنت ، والحفر في كود lib والتخمين العشوائي ، توصلت إلى الاستنتاج التالي: إنه ممكن! :د
/public/fonts/fonts.css
، الذي يعرّف @ font-faces:@font-face {
font-family: 'inglobal';
font-weight: normal;
font-style: normal;
src: url('./inglobal.ttf');
}
أضف <link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
إلى رأس /public/index.html
يا هلا!
4 / ب. إذا لم تنجح ، لأي سبب من الأسباب ، فغيّر امتدادات الخطوط إلى .css (أيضًا بسعر src: url('./OperatorMono.css')
)
ربط خطوط google في index.html الخاص بك
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap" rel="stylesheet">
أضف في أسلوب جسمك
/* Styles */
body {
margin: 0 auto;
font-family: 'Montserrat';
}
تغييرات قليلة في app.js
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
const theme = createMuiTheme({
typography: {
fontFamily: [
'Montserrat'
].join(','),
},
})
/public/index.html
عملت لي :)
في الواقع ، بعد 6 ساعات من البحث على الإنترنت ، والحفر في كود lib والتخمين العشوائي ، توصلت إلى الاستنتاج التالي: إنه ممكن! :د
- إنشاء / دليل الخطوط في / public
- أنشئ
/public/fonts/fonts.css
، الذي يعرّف @ font-faces:@font-face { font-family: 'inglobal'; font-weight: normal; font-style: normal; src: url('./inglobal.ttf'); }
- أضف
<link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
إلى رأس /public/index.html- يا هلا!
4 / ب. إذا لم تنجح ، لأي سبب من الأسباب ، فغيّر امتدادات الخطوط إلى .css (أيضًا بسعر
src: url('./OperatorMono.css')
)
إنه عمل !! شكرا لك.
اتبع هاتين الخطوتين لتغيير الخط الافتراضي:
أنا هنا أقوم بتغيير الخط الافتراضي إلى "Open Sans"
استيراد خطوط Google في index.html الخاص بك
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet"/>
قم بإجراء هذه التغييرات في index.js
import { ThemeProvider } from '@material-ui/styles';
import { CssBaseline } from '@material-ui/core';
import { createMuiTheme } from '@material-ui/core';
const theme = createMuiTheme({ typography: { fontFamily: [ 'Open Sans' ].join(','), }, })
ReactDOM.render(
<ThemeProvider theme={theme}>
<CssBaseline />
<App />
</ThemeProvider>,
document.getElementById('root')
);
_أحيانًا يكون التسلسل مهمًا أثناء التكوين. كممارسة جيدة ، حدد الطباعة دائمًا في المستوى الأعلى أثناء التكوين في createMuiTheme _
بعد سمة التكوين لم يتم الحصول على عائلة الخطوط
// Create a theme instance.
const theme = createMuiTheme({
palette: {
primary: {
main: "#2991d6",
},
secondary: {
main: "#19857b",
},
error: {
main: red.A400,
},
background: {
default: "#fff",
},
}, typography: {
fontFamily: "VarelaRound,sans-serif",
},
overrides: {
MuiCssBaseline: {
"@global": {
"@font-face": [varelaRound],
},
},
},
});
Note:
In this case Material UI using Roboto as the default font
// Create a theme instance.
const theme = createMuiTheme({
typography: {
fontFamily: "VarelaRound,sans-serif",
},
palette: {
primary: {
main: "#2991d6",
},
secondary: {
main: "#19857b",
},
error: {
main: red.A400,
},
background: {
default: "#fff",
},
},
overrides: {
MuiCssBaseline: {
"@global": {
"@font-face": [varelaRound],
},
},
},
});
أنا فقط أغير التسلسل وكل شيء يعمل بشكل جيد.
التعليق الأكثر فائدة
في الواقع ، بعد 6 ساعات من البحث على الإنترنت ، والحفر في كود lib والتخمين العشوائي ، توصلت إلى الاستنتاج التالي: إنه ممكن! :د
/public/fonts/fonts.css
، الذي يعرّف @ font-faces:أضف
<link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
إلى رأس /public/index.htmlيا هلا!
4 / ب. إذا لم تنجح ، لأي سبب من الأسباب ، فغيّر امتدادات الخطوط إلى .css (أيضًا بسعر
src: url('./OperatorMono.css')
)